Issue Token
1 min
An almost unique feature of Signum is the native token engine, which does not require any Smart Contract. This makes tokenization efficient, secure and cheap. Issuing a token costs 150 SIGNA. You can define its name (up to ten alphanumeric characters), the divisibility (between zero and eight decimals) and if a token should have a fixed supply, or being mintable. Once you know how to sign transactions with SignumJS, it is pretty straightforward to issue a new token.
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 issueToken(args) {
try {
const {ledgerType, name, description, supply, mintable, decimals, 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)
// Issuing a token costs 150 SIGNA
const feePlanck = Amount.fromSigna(150).getPlanck()
// 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(supply).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.issueAsset({
name,
description,
decimals,
mintable,
quantity,
feePlanck,
senderPublicKey,
senderPrivateKey
})
// now, some final nice message
console.info(`Token ${name} successfully created - Token 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',
name: 'INDI2000',
description: 'A 1000 chars description...'
supply: 100,
decimals: 4,
mintable: false,
passphrase: 'YourVerySecretPassphraseWhichCannotBeRevealedHere'
});
})();