Development
...
Dispatch Transactions
Mint Token
1 min
minting a token is easy also the requirement is that a token is mintable, which is defined on its issuance const {ledgerclientfactory} = require("@signumjs/core"); const {chainvalue, amount} = require("@signumjs/util"); const {generatemasterkeys} = require("@signumjs/crypto"); const ledgerhosturls = { testnet 'http //localhost 6876', mainnet 'https //europe signum network', } async function minttoken(args) { try { const {ledgertype, tokenid, tomint, passphrase} = args // we create our client depending on the parameter const ledger = ledgerclientfactory create({ nodehost ledgerhosturls\[ledgertype]) } // before we can send we need to get the private signing key from the user const {publickey senderpublickey, signprivatekey senderprivatekey} = generatemasterkeys(passphrase) // now, we check the token for existance, but also fetching its decimals // such we can compute the quantity to be minted console info("checking token ") const {decimals, name} = await ledger asset getasset({assetid tokenid}) // the token quantity is being determined by the given supply and decimals it's similar to the concept of signa vs planck, // but with dynamic decimals (0 8) the formula to calculate the quantity is qnt = amount (10^decimals) // to simplify the devs life we can use the value object `chainvalue` which allows us to convert from and to quantity // instead of using the name planck/signa the name atomic/compound is used const quantity = chainvalue create(decimals) setcompound(tomint) getatomic() // 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 asset mintasset({ assetid tokenid, quantity, feeplanck amount fromsigna(0 01) getplanck(), senderpublickey, senderprivatekey }) // now, some final nice message console info(`minted ${amount} new coins of token ${name} transaction id ${transaction}`) } 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 issuetoken({ ledgertype 'testnet', tokenid '1234', tomint 100, passphrase 'yourverysecretpassphrasewhichcannotberevealedhere' }); })();