Development
...
Dispatch Transactions
Send Signa
1 min
one of the most crucial operations is the transfer of signa from one account to another so, without much blabla, we hop directly into the code const {address, addressprefix, ledgerclientfactory} = require("@signumjs/core"); const {amount, currencysymbol} = require("@signumjs/util"); const {generatemasterkeys} = require("@signumjs/crypto"); const ledgerhosturls = { testnet 'http //localhost 6876', mainnet 'https //europe signum network', } async function sendsigna(args) { try { const {ledgertype, recipient, amount, feetype, passphrase} = args // we create our client depending on the parameter const ledger = ledgerclientfactory create({ nodehost ledgerhosturls\[ledgertype]) } // we check if incoming account is either a signum address, or numeric id // eventually, we convert to numeric id, if the value is invalid an error will be thrown const recipientid = address create(recipient) getnumericid() // now we check if the account exists if it does not exist the method throws an // exception and the further flow is interrupted // using exception to assert certain conditions is imho more robust than checking returned // values with if statements the code is much cleaner console info("verifying recipient ") await ledger account getaccount({accountid recipientid}) // before we can send we need to get the private signing key from the user const {publickey, signprivatekey} = generatemasterkeys(passphrase) // as a next step, we use the systems fee suggestion mechanism to give us the current costs for the chosen // fee type in this example we let it flexible, but you can fix the fee costs to a minimum, i e 0,00735 signa const suggestedfees = await ledger network getsuggestedfees() // we assume that the feetype is either \['minimum', 'cheap', 'standard', 'priority'] const selectedfeeplanck = suggestedfees\[feetype tolowercase()] // 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 signinh, but never sent over the network const {transaction} = await ledger transaction sendamounttosinglerecipient({ recipientid, amountplanck amount fromsigna(amount) getplanck(), feeplanck selectedfeeplanck, senderprivatekey signprivatekey, senderpublickey publickey }); // now, some final nice message const addressprefix = ledgertype === 'mainnet' ? addressprefix mainnet addressprefix testnet console info(`successfully sent ${amount} ${currencysymbol} to ${address create(recipientid, addressprefix) getreedsolomonaddress()} transaction id ${transaction}`) console info(`you paid a total of ${amount fromsigna(amount) add(amount fromplanck(selectedfeeplanck)) tostring()}`) } catch (e) { // if the api returns an exception, // the return error object is of type httperror handleerror(e); } } // // our entry point has to be async, as our subsequent calls are // // this pattern keeps your app running until all async calls are executed (async () => { await sendsigna({ ledgertype 'testnet', recipient 'ts qaja qw5y swvp 4rvp4', amount 100 00, feetype 'cheap', passphrase 'yourverysecretpassphrasewhichcannotberevealedhere' }); })(); so, the crucial part is the signing of the transaction it is required to get the signprivatekey from the key set, that's being derived from the seed the private keys must never be passed to other persons, or even hard coded into code you need to establish mechanism to secure either the private keys, or the seed that generates the keys without the seed/private key it is not possible to sign a transaction, i e all balance of that account is not accessible