Development
...
Recipes
Dispatch Transactions
4 min
broadcasting transactions requires slightly more effort, due to the signing process in signumjs all transactions are signed locally, that is no secret is ever sent over the wire to sign the transaction you need the private signing key, which can be obtained by the generatemasterkeys function all functions that requires signing in signumjs can work in two modes automatic signing manual signing automatic signing for the most common cases, the developer has somehow access to a private key, may it by asking the user for his passphrase, and/or having the necessary keys securely stored somewhere, for example as environment variable on the server, or in an encrypted form on the clients browser everytime the signprivatekey is provided, signumjs automatically uses the key, signs and broadcasts the transaction // before we can send we need to get the private signing key from the user const {publickey, signprivatekey} = generatemasterkeys(passphrase) // now, we execute the transaction // within the method the local signing flow is being executed, i e // the private key is used only locally for signing, but never sent over the network const {transaction} = await ledger transaction sendamounttosinglerecipient({ recipientid, amountplanck amount fromsigna(amount) getplanck(), feeplanck selectedfeeplanck, senderprivatekey signprivatekey, // <<< causes automatic signing senderpublickey publickey }); manual signing in contrast to automatic signing, it is also possible to sign and broadcast a transaction manually actually, this is most commonly used in conjunction with the xt wallet the xt wallet securely manages the keys of an user and thus the wallet can be used as "signer" this way, the developer does not take care of securing an users keys (which can be an annoying and also risky task), and simply sends the unsigned transaction bytes to the wallet it is not possible to request unsigned bytes on one node and use another node for broadcasting async function sendmessage() { const recipientid = getrecipientaccountid() const message = getmessage() try { // here,we do not provide a private key, and this way the node returns // not an transaction object, but the unsigned byte sequence const {unsignedtransactionbytes} = await window\ signumledger message sendmessage({ feeplanck calcfee(), recipientid, message, messageistext true, senderpublickey window\ wallet connection publickey // no private key provided }) // now, we send the unsigned transaction to the wallet, which manages // the users keys this way, the developer does not take care about // managing accounts this is the recommended way for dapps const {transaction} = await window\ wallet confirm(unsignedtransactionbytes) showsuccess(`message sent successfully id ${transaction}`) } catch (e) { showerror(e message) } }