---
title: Mint Token
slug: signum/mint-token
createdAt: 2022-09-07T20:52:16.000Z
---

Minting a token is easy also. The requirement is that a token is mintable, which is defined on its issuance.

```javascript
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'
    });
})();
```
