Create and send your Cardano Native token using Daedalus node

Creating native token

Before all, save some environmental variables, so cardano-cli uses Daedalus. This example uses testnet, however you can replace it to use Mainnet easily.
1
export TESTNET_ID=1097911063 #testned ID
2
export CARDANO_NODE_SOCKET_PATH=~/Library/Application\ Support/Daedalus\ Testnet/cardano-node.socket
3
alias cardano-cli="/Applications/Daedalus\ Testnet.app/Contents/MacOS/cardano-cli"# Save
Copied!
Declare name and amount of tokens.
1
export TOKEN_NAME=tAADA
2
export TOKEN_AMOUNT=100000000
Copied!
​
Next, you will need to generate account keys and payment address:
1
# Generate stake keys
2
cardano-cli stake-address key-gen \
3
--verification-key-file stake.vkey \
4
--signing-key-file stake.skey
5
​
6
# Generate payment keys
7
cardano-cli address key-gen \
8
--verification-key-file payment.vkey \
9
--signing-key-file payment.skey
10
​
11
# Use payment and stake verification keys to generate a payment address
12
cardano-cli address build \
13
--payment-verification-key-file payment.vkey \
14
--stake-verification-key-file stake.vkey \
15
--out-file payment.addr \
16
--testnet-magic $TESTNET_ID
Copied!
Make sure to request tADA to your wallet so you have what to send. You can do it here.
Once done, you should start seeing amount after running this code:
1
# Check address balance
2
cardano-cli query utxo --address $(< payment.addr) \
3
--testnet-magic $TESTNET_ID
Copied!
Next export protocol and generate policy which basically is your token ID.
1
# Export the protocol parameters to a file for later use
2
cardano-cli query protocol-parameters \
3
--testnet-magic $TESTNET_ID \
4
--out-file protocol.json
5
​
6
# Create directory for policy files
7
mkdir policy
8
​
9
# Generate policy signing and verification keys
10
cardano-cli address key-gen \
11
--verification-key-file policy/policy.vkey \
12
--signing-key-file policy/policy.skey
13
​
14
# Create policy script file
15
touch policy/policy.script && echo "" > policy/policy.script
16
​
17
# Generate policy script and put it into the newly created file
18
echo "{" >> policy/policy.script
19
echo " \"keyHash\": \"$(cardano-cli address key-hash --payment-verification-key-file policy/policy.vkey)\"," >> policy/policy.script
20
echo " \"type\": \"sig\"" >> policy/policy.script
21
echo "}" >> policy/policy.script
22
​
23
# Generate policy ID
24
cardano-cli transaction policyid --script-file ./policy/policy.script >> policy/policyId
Copied!
Next you will need to declare transaction details and sign the transaction:
1
# Save this data as environment variables
2
export TX_HASH=fc11c042977a26ed4d5ac5e1120d8d53ac1458cce3bb919cb441b15bd087d2b4
3
export TX_IX=0
4
export AVAILABLE_LOVELACE=1000000000
5
​
6
# Build raw transaction using this data
7
cardano-cli transaction build-raw \
8
--fee 0 \
9
--tx-in $TX_HASH#$TX_IX \
10
--tx-out $(< payment.addr)+"$(($AVAILABLE_LOVELACE - $TX_FEE))"+"$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \
11
--mint="$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \
12
--out-file matx.raw
13
​
14
# Calculate the minimum fee
15
cardano-cli transaction calculate-min-fee \
16
--tx-body-file matx.raw \
17
--tx-in-count 1 \
18
--tx-out-count 1 \
19
--witness-count 1 \
20
--testnet-magic $TESTNET_ID \
21
--protocol-params-file protocol.json
22
​
23
# Make your fee available as an environment variable
24
export TX_FEE=174961 # Replace with value returned by running the previous command
25
​
26
# Use the calculated fee to build the transaction with proper fee amount
27
cardano-cli transaction build-raw \
28
--fee $TX_FEE \
29
--tx-in $TX_HASH#$TX_IX \
30
--tx-out $(< payment.addr)+$(($AVAILABLE_LOVELACE - $TX_FEE))+"$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \
31
--mint="$TOKEN_AMOUNT $(< policy/policyId).$TOKEN_NAME" \
32
--out-file matx.raw
33
​
34
# Sign the transaction
35
cardano-cli transaction sign \
36
--signing-key-file payment.skey \
37
--signing-key-file policy/policy.skey \
38
--script-file policy/policy.script \
39
--testnet-magic $TESTNET_ID \
40
--tx-body-file matx.raw \
41
--out-file matx.signed
42
​
43
# Submit the transaction
44
cardano-cli transaction submit --tx-file matx.signed --testnet-magic $TESTNET_ID
Copied!
Now you should have new token in the address you sent tADA initialy to. You can check it with:
1
cardano-cli query utxo --address $(< payment.addr) \
2
--testnet-magic $TESTNET_ID
Copied!
Voalia. You have your own token.

Sending the token

This tutorial was done using Daedalus wallet from MacOS. Using Daedalus makes sure you don't need to pull the whole Cardano blockchain.
Next, we need to generate new payment pair to which we will transact to:
1
# generate payment pair
2
cardano-cli address key-gen \
3
--verification-key-file payment2.vkey \
4
--signing-key-file payment2.skey
Copied!
Now, generate payment2 address and protocol.json to which will be used for transaction.
1
-- Generate address #2
2
cardano-cli address build \
3
--payment-verification-key-file payment2.vkey \
4
--stake-verification-key-file stake.vkey \
5
--out-file payment2.addr \
6
--testnet-magic $TESTNET_ID
7
​
8
cardano-cli query protocol-parameters \
9
--testnet-magic $TESTNET_ID \
10
--out-file protocol.json
Copied!
Find latest UTXO of the address (you need a hash key)
1
cardano-cli query protocol-parameters \
2
--testnet-magic $TESTNET_ID \
3
--out-file protocol.json
4
5
# Save your hash into parameter
6
TX_HASH=fc11c042977a26ed4d5ac5e1120d8d53ac1458cce3bb919cb441b15bd087d2b4
7
TX_IX=1
8
LOVELACE_BALANCE=997643830
9
TIME_TO_LIVE=271200
Copied!
Next, we can start building Transaction:
1
# build raw file to calculate FEE
2
cardano-cli transaction build-raw \
3
--fee 0 \
4
--tx-in $TX_HASH#$TX_IX \
5
--tx-out $(cat payment.addr)+0 \
6
--tx-out $(cat payment2.addr)+0 \
7
--out-file tx.raw
8
9
10
# calculate tx fee
11
cardano-cli transaction calculate-min-fee \
12
--tx-body-file tx.raw \
13
--tx-in-count 1 \
14
--tx-out-count 2 \
15
--witness-count 2 \
16
--testnet-magic $TESTNET_ID \
17
--protocol-params-file protocol.json
18
19
20
# Add fee amount from above. Edit AMT_TO_SEND if you want to send different amount
21
FEES=187589
22
AMT_TO_SEND=2000000
23
TX_OUT=$(($LOVELACE_BALANCE - $AMT_TO_SEND - $FEES))
24
​
25
# build final transaction raw file
26
# MAKE sure that all amount from UTXO is sent out. For example if UTXO has 100 ADA and you want to send 20. Make sure to send left 80 back to same wallet
27
cardano-cli transaction build-raw \
28
--tx-in "$TX_HASH#$TX_IX" \
29
--tx-out $(cat payment2.addr)+$AMT_TO_SEND+"10000 1a22f0104744353538b609676048adc9e885d060093ec1f0ea29850d.tAADA" \
30
--tx-out $(cat payment.addr)+$TX_OUT+"90000 1a22f0104744353538b609676048adc9e885d060093ec1f0ea29850d.tAADA" \
31
--ttl $TIME_TO_LIVE \
32
--fee $FEES \
33
--out-file tx.raw
34
35
# Sign transaction
36
cardano-cli transaction sign \
37
--tx-body-file tx.raw \
38
--signing-key-file payment.skey \
39
--testnet-magic $TESTNET_ID \
40
--out-file tx.signed
41
​
42
# submit transaction
43
cardano-cli shelley transaction submit \
44
--tx-file tx.signed \
45
--testnet-magic $TESTNET_ID
Copied!
Last modified 5mo ago