Searchโ€ฆ
Cardano Native Asset (NFT) ๐Ÿ’ฐ
Let's make some native assets on Cardano โค๏ธโœจ

THIS GUIDE IS DEPRECEATED

Who is this guide for?

  • For people who want to make NFT's or Native Assets on Cardano
  • For people who know about Cardano

Benefits of NFT's on Cardano

  • Low transaction fees
  • Native on the blockchain

Prerequisites

We made this tutorial for use with Raspberry-Pi-ARM machines running on Linux OS so make sure to download the correct node.js for your local machine/CPU and OS. Currently, the Cardano-node and Cardano-cli are meant to be built from source on Linux machines. Any other OS will have its own build complexities, and we do not cover them in any of our tutorials as of right now. How to build Cardano Node from sourceโ€‹
If you are using a Raspberry Pi machine here is an easy-to-follow tutorial we made to get a Cardano Relay Node running.
  • cardano-node / cardano-cli set up on local machine
  • Make sure you have a Cardano node running and fully synced to the database
  • Make sure node.js installed
1
#Copy/Paste this into your terminal if node.js is not installed
2
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
3
sudo apt-get install -y nodejs
Copied!

Verify everything is set up properly on our machine โš™๏ธ

1
#Copy/paste into terminal window
2
cardano-cli version; cardano-node version
Copied!
Your output should look like this ๐Ÿ‘‡
1
cardano-cli 1.30.1 - linux-aarch64 - ghc-8.10
2
git rev 0000000000000000000000000000000000000000
3
cardano-node 1.30.1 - linux-aarch64 - ghc-8.10
4
git rev 0000000000000000000000000000000000000000
Copied!

Verify our node.js version is correct and is on v14.16.1

1
#Copy/paste into terminal window
2
node -v
Copied!
1
v14.18.1
Copied!

Video Walk-through:

Create our project directory and initial setup

Make sure our $NODE_HOME environment variable exists
1
# check for $NODE_HOME
2
echo $NODE_HOME
Copied!
If the above command didn't return anything, you need to set the$NODE_HOMEbash environment variable or use a static path for the Cardano node's socket location indbC in your Cardano node directory.
1
export NODE_HOME="/home/ada/pi-pool"
2
# Change this to where cardano-node creates socket
3
export CARDANO_NODE_SOCKET_PATH="$NODE_HOME/db/socket"
Copied!
Now let's make our projects directory then create our package.json file and install the cardanocli-js package.
1
mkdir cardano-minter
2
cd cardano-minter
3
npm init -y #creates package.json)
4
npm install cardanocli-js --save
Copied!
  1. 1.
    Copy the Cardano node genesis latest build number from the IOHK hydra website
  2. 2.
    Create a bash shell script to Download the latest Genesis config file needed
1
nano fetch-config.sh
Copied!
TESTNET
MAINNET
1
echo export NODE_BUILD_NUM=$(curl https://hydra.iohk.io/job/Cardano/iohk-nix/cardano-deployment/latest-finished/download/1/index.html | grep -e "build" | sed 's/.*build\/\([0-9]*\)\/download.*/\1/g') >> $HOME/.bashrc
2
wget -N https://hydra.iohk.io/build/${NODE_BUILD_NUM}/download/1/testnet-shelley-genesis.json
Copied!
1
echo export NODE_BUILD_NUM=$(curl https://hydra.iohk.io/job/Cardano/iohk-nix/cardano-deployment/latest-finished/download/1/index.html | grep -e "build" | sed 's/.*build\/\([0-9]*\)\/download.*/\1/g') >> $HOME/.bashrc
2
wget -N https://hydra.iohk.io/build/${NODE_BUILD_NUM}/download/1/mainnet-shelley-genesis.json
Copied!
Now we need to give permissions to our new script to execute then we will run our script and download the genesis files.
1
sudo chmod +x fetch-config.sh
2
./fetch-config.sh
Copied!

Next, we make our src folder/directory and then create the Cardano client.

1
mkdir src
2
cd src
3
nano cardano.js
Copied!
If you are using testnet make sure you have the correct testnet-magic version number. You can find the current testnet version here or simply look in your testnet-shelley-genesis.json file in your cardano node directory.
โ€‹
MAINNET
TESTNET
1
const Cardano = require("cardanocli-js");
2
โ€‹
3
const cardano = new Cardano({
4
network: "mainnet",
5
dir: __dirname + "/../",
6
shelleyGenesisPath: __dirname + "/../mainnet-shelley-genesis.json",
7
});
8
โ€‹
9
module.exports = cardano;
Copied!
1
const Cardano = require("cardanocli-js")
2
โ€‹
3
const cardano = new Cardano({
4
network: "testnet-magic 1097911063",
5
dir: __dirname + "/../",
6
shelleyGenesisPath: __dirname + "/../testnet-shelley-genesis.json"
7
});
8
โ€‹
9
module.exports = cardano;
Copied!

Video Walk-through :

Create Project
Get Cardano genisis files
Setup Cardano js client
โ€‹
โ€‹
โ€‹
โ€‹
โ€‹

Create a local wallet

1
nano create-wallet.js
Copied!
1
const cardano = require('./cardano')
2
โ€‹
3
const createWallet = (account) => {
4
const payment = cardano.addressKeyGen(account);
5
const stake = cardano.stakeAddressKeyGen(account);
6
cardano.stakeAddressBuild(account);
7
cardano.addressBuild(account, {
8
paymentVkey: payment.vkey,
9
stakeVkey: stake.vkey,
10
});
11
return cardano.wallet(account);
12
};
13
โ€‹
14
createWallet("ADAPI")
Copied!
1
cd ..
2
node src/create-wallet.js
Copied!

Verify balance wallet balance is Zero, then we fund the wallet

  • First, we need to create a get-balance.js script
1
cd src
2
nano get-balance.js
Copied!
1
// create get-balance.js
2
const cardano = require('./cardano')
3
โ€‹
4
const sender = cardano.wallet("ADAPI");
5
โ€‹
6
console.log(
7
sender.balance()
8
)
Copied!
  • Now, Check the balance of our wallet.
1
cd ..
2
node src/get-balance.js
Copied!
  • We can go ahead and send some funds (ADA) into our wallet we created, wait a few minutes, and then check the balance again to make sure the transaction was successful.
If you are using testnet you must get your tADA from the testnet faucet here.

Video Walk-through :

Untitled
โ€‹

Mint our Native-Asset/NFT on Cardano

Before we proceed to mint our Native Asset we must have a few things taken care of. We need to first get our "asset" onto our IPFS node and generate the IPFS link. If you do not know about IPFS or what it actually does we recommend having a read through the documentation here or watching this video.
Since we are using an image file to be our asset we should upload a smaller thumbnail-sized version of our image (ideally less than 1MB). This will be used on sites like pool.pm to display our assets nicely in our wallets. We then upload the full-size image as our source image.
  • Download IPFSโ€‹
  • Upload your asset's files to IPFS
  • Get our image thumbnail IPFS link
  • Get the src IPFS link

For reference:

  • image (thumbnail version) - ipfs://QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE
  • src (full-size version) - ipfs://Qmaou5UzxPmPKVVTM9GzXPrDufP55EDZCtQmpy3T64ab9N

Create our mint-asset.js script

This script has three main components:
  1. 1.
    Generate policy id
  2. 2.
    Define your metadata
  3. 3.
    Create mint transaction
1
nano mint-asset.js
Copied!
1
const cardano = require("./cardano")
2
โ€‹
3
// 1. Get the wallet
4
โ€‹
5
const wallet = cardano.wallet("ADAPI")
6
โ€‹
7
// 2. Define mint script
8
โ€‹
9
const mintScript = {
10
keyHash: cardano.addressKeyHash(wallet.name),
11
type: "sig"
12
}
13
โ€‹
14
// 3. Create POLICY_ID
15
โ€‹
16
const POLICY_ID = cardano.transactionPolicyid(mintScript)
17
โ€‹
18
// 4. Define ASSET_NAME
19
โ€‹
20
const ASSET_NAME = "BerrySpaceGreen"
21
โ€‹
22
// 5. Create ASSET_ID
23
โ€‹
24
const ASSET_ID = POLICY_ID + "." + ASSET_NAME
25
โ€‹
26
// 6. Define metadata
27
โ€‹
28
const metadata = {
29
721: {
30
[POLICY_ID]: {
31
[ASSET_NAME]: {
32
name: ASSET_NAME,
33
image: "ipfs://QmQqzMTavQgT4f4T5v6PWBp7XNKtoPmC9jvn12WPT3gkSE",
34
description: "Super Fancy Berry Space Green NFT",
35
type: "image/png",
36
src: "ipfs://Qmaou5UzxPmPKVVTM9GzXPrDufP55EDZCtQmpy3T64ab9N",
37
// other properties of your choice
38
authors: ["PIADA", "SBLYR"]
39
}
40
}
41
}
42
}
43
โ€‹
44
// 7. Define transaction
45
โ€‹
46
const tx = {
47
txIn: wallet.balance().utxo,
48
txOut: [
49
{
50
address: wallet.paymentAddr,
51
value: { ...wallet.balance().value, [ASSET_ID]: 1 }
52
}
53
],
54
mint: {
55
actions: [{ type: "mint", quantity: 1, asset: ASSET_ID }],
56
script: [mintScript]
57
},
58
metadata,
59
witnessCount: 2
60
}
61
โ€‹
62
// 8. Build transaction
63
โ€‹
64
const buildTransaction = (tx) => {
65
โ€‹
66
const raw = cardano.transactionBuildRaw(tx)
67
const fee = cardano.transactionCalculateMinFee({
68
...tx,
69
txBody: raw
70
})
71
โ€‹
72
tx.txOut[0].value.lovelace -= fee
73
โ€‹
74
return cardano.transactionBuildRaw({ ...tx, fee })
75
}
76
โ€‹
77
const raw = buildTransaction(tx)
78
โ€‹
79
// 9. Sign transaction
80
โ€‹
81
const signTransaction = (wallet, tx) => {
82
โ€‹
83
return cardano.transactionSign({
84
signingKeys: [wallet.payment.skey, wallet.payment.skey],
85
txBody: tx
86
})
87
}
88
โ€‹
89
const signed = signTransaction(wallet, raw)
90
โ€‹
91
// 10. Submit transaction
92
โ€‹
93
const txHash = cardano.transactionSubmit(signed)
94
โ€‹
95
console.log(txHash)
Copied!
  • Run the minting script, then wait a few moments to check the balance in our wallet
1
cd ..
2
node src/mint-asset.js
Copied!
Video Walk-through:
Untitled
โ€‹

Sending your NFT back to Daedulus or Yoroi wallet

Now we must create a new script to send our newly minted NFT to a wallet.
1
cd cardaon-minter/src
2
nano send-back-asset-to-wallet.js
Copied!
There are few main parts we have to this script in order to send the asset:
  1. 1.
    Get the wallet
  2. 2.
    Define the transaction
  3. 3.
    Build the transaction
  4. 4.
    Calculate the fee
  5. 5.
    Pay the fee by subtracting it from the sender's utxo
  6. 6.
    Build the final transaction
  7. 7.
    Sign the transaction
  8. 8.
    Submit the transaction
1
const cardano = require("./cardano")
2
โ€‹
3
// 1. get the wallet
4
โ€‹
5
const sender = cardano.wallet("ADAPI")
6
โ€‹
7
// 2. define the transaction
8
โ€‹
9
console.log(
10
"Balance of Sender wallet: " +
11
cardano.toAda(sender.balance().value.lovelace) + " ADA"
12
)
13
โ€‹
14
const receiver = "addr1qym6pxg9q4ussr96c9e6xjdf2ajjdmwyjknwculadjya488pqap23lgmrz38glvuz8qlzdxyarygwgu3knznwhnrq92q0t2dv0"
15
โ€‹
16
const txInfo = {
17
txIn: cardano.queryUtxo(sender.paymentAddr),
18
txOut: [
19
{
20
address: sender.paymentAddr,
21
value: {
22
lovelace: sender.balance().value.lovelace - cardano.toLovelace(1.5)
23
}
24
},
25
{
26
address: receiver,
27
value: {
28
lovelace: cardano.toLovelace(1.5),
29
"ad9c09fa0a62ee42fb9555ef7d7d58e782fa74687a23b62caf3a8025.BerrySpaceGreen": 1
30
}
31
}
32
]
33
}
34
โ€‹
35
// 3. build the transaction
36
โ€‹
37
const raw = cardano.transactionBuildRaw(txInfo)
38
โ€‹
39
// 4. calculate the fee
40
โ€‹
41
const fee = cardano.transactionCalculateMinFee({
42
...txInfo,
43
txBody: raw,
44
witnessCount: 1
45
})
46
โ€‹
47
// 5. pay the fee by subtracting it from the sender utxo
48
โ€‹
49
txInfo.txOut[0].value.lovelace -= fee
50
โ€‹
51
// 6. build the final transaction
52
โ€‹
53
const tx = cardano.transactionBuildRaw({ ...txInfo, fee })
54
โ€‹
55
// 7. sign the transaction
56
โ€‹
57
const txSigned = cardano.transactionSign({
58
txBody: tx,
59
signingKeys: [sender.payment.skey]
60
})
61
โ€‹
62
// 8. submit the transaction
63
โ€‹
64
const txHash = cardano.transactionSubmit(txSigned)
65
โ€‹
66
console.log(txHash)
Copied!
1
cd ..
2
node src/send-back-asset-to-wallet.js
Copied!

Final Steps to view your NFT

  1. 1.
    View your nft in your wallet
  2. 2.
    View your asset on cardanoassets.com
  3. 3.
    View your asset on pool.pm (see the actual picture)
  4. 4.
    Show the original minting metadata
  5. 5.
    Open the src and image ipfs links in your browser to prove that it worked

Video Walk-through:

If you liked this tutorial and want to see more like it please consider staking your ADA with any of our Alliance's Stake Pools, or giving a one-time donation to our Alliance https://cointr.ee/armada-alliance.
Last modified 11d ago