Skip to main content

Minting transactions

The ability to create and manage custom tokens is one of the distinguishing features of the Cardano blockchain. Minting refers to the process of 'producing new tokens, either as part of an initial coin offering (ICO) or ongoing token issuance'. Minting transactions enable users to generate or burn tokens according to predefined rules. This tutorial explores the details of minting transactions on Cardano.

Consider a scenario where Bob wants to give Alice a token, but only Bob has the minting authority for that token. To achieve this, Bob needs to create a script that defines the minting and burning rules. There are two approaches to accomplish this: using Plutus policy scripts or simple multi-signature scripts. In this case, the tutorial suggests using a simple multi-signature script since the rule is straightforward: only Bob can mint the token.

Before you begin, ensure that you have all the necessary components ready. First, you need to generate new keys for the script itself. The process for obtaining script keys is as follows:

$ cardano-cli address key-gen \
--verification-key-file transactions-tutorial-policy/policy.vkey \
--signing-key-file transactions-tutorial-policy/policy.skey

Before creating the script, you need to get the key hash of the new keys:

$ cardano-cli address key-hash \
--payment-verification-key-file transactions-tutorial-policy/policy.vkey
8ebd5f9c84fc25ae4506c7d0b687b2f7e82fe3f891036833e7f25c9b

You can now create the script by writing the following code into transactions-tutorial-policy/policy.script:

{
“keyHash”: “8ebd5f9c84fc25ae4506c7d0b687b2f7e82fe3f891036833e7f25c9b”,
“type”: “sig”
}

You can get the PolicyId with the following command:

$ cardano-cli transaction policyid \
--script-file transactions-tutorial-policy/policy.script
C38b0924e32e677f7787f0a0247b177588ec135db927688d8a63310a

It is also helpful to store it in an environment variable:

export POLICY_ID=C38b0924e32e677f7787f0a0247b177588ec135db927688d8a63310a

Now, you need to create a token name, which has to be in hexadecimal (54657374546F6B656E):

export TOKEN_NAME=54657374546F6B656E

Build the transaction:

cardano-cli transaction build \
--tx-in f947f84f1156995afd695247a8dc8a508fd40d371ce0afb801029769a0104874#0 \
--mint "1 $(echo $POLICY_ID).$(echo $TOKEN_NAME)" \
--testnet-magic 1 \
--change-address $(cat bob.addr) \
--mint-script-file ../cardano/transactions-tutorial-policy/policy.script \
--out-file minting.tx \
--tx-out "$(cat alice.addr)+1047330+1 $(echo $POLICY_ID).$(echo $TOKEN_NAME)"