Development
...
Smart Contracts
Publish Smart Contract
1 min
although, it is not possible to compile smart contracts with signumjs, it is possible to deploy them usually, you'll need to deploy smart contracts only programmatically, if you need to create many instances of the same contract this examples shows how to deploy a contract by its reference deploying smart contracts by reference is a very efficient way, as no redundant space in the chain is occupied, it is cheaper and more contracts per block can be deployed this feature is unique to signum and called https //github com/signum network/sips/blob/master/sip/sip 30 md for this example, we assume a ficticious contract the crucial part is the use of the referencedtransactionhash the hash is available inside the transaction of the first deployment of the contracts code, which should be done before using either https //github com/signum network/signum smartj or https //github com/deleterium/smartc/tree/main/docs use the explorer to get the full hash of the deployed contract const {generatemasterkeys} = require("@signumjs/crypto"); const {ledgerclientfactory} = require("@signumjs/core"); const {amount, chainvalue, converthexstringtodecstring, converthexendianess, convertstringtohexstring} = require("@signumjs/util"); const ledgerhosturls = { testnet 'http //localhost 6876', mainnet 'https //europe signum network', } / this is an example how to create a new green contract (by referencing existing code) it also shows how to initialize the new contract with its own data note this example rather demonstrates how to do it it's non working due to non existent contract / async function publishgreencontract({passphrase, name, decimals, amount}) { try { // we create our client depending on the parameter const ledger = ledgerclientfactory create({ nodehost ledgerhosturls\[ledgertype]) } const senderkeys = generatemasterkeys(passphrase); // let's assume we have a contract with the following variable stack to be initialized // 0 token name // 1 token decimals // 2 quantity to be issued // see also https //github com/signum network/signumjs/issues/26 const tokenname = converthexstringtodecstring( converthexendianess( convertstringtohexstring(name) )) const tokendecimals = decimals const tokenquantity = chainvalue create(tokendecimals) setcompound(amount) getatomic() // this reference you get from the previous/first deployment of the contract, which serves as a template // think of it like classes and objects in object oriented programming // example how to get the full hash https //t chain signum network/tx/14079727760708466474 const contractreference = '2af73bffcc3d65c3df8063c42c75764cd1d22025a22911bb3bc7dc761a23374f' // now that we have all the params we can publish a new contract instance with our custom data const {transaction} = await ledger contract publishcontractbyreference({ referencedtransactionhash contractreference, feeplanck amount fromsigna(155) getplanck(), // as the imaginary contract issues a token, we need to send at least 150 signa data \[ tokenname, tokendecimals, tokenquantity ], senderpublickey senderkeys publickey, senderprivatekey senderkeys signprivatekey }) console info('contract deployed successfully tx id ', transaction) } catch (e) { // if the api returns an exception, // the return error object is of type httperror console error(e); } } (async () => { await publishgreencontract({ name 'newtoken', decimals 2, amount 1 000 000, passphrase 'yourverysecretpassphrasewhichcannotberevealedhere' }); })();