Cardano: Submit Cardano Blockchain Transactions with Embedded Metadata Stored on Filebase

Learn how to submit Cardano blockchain transactions with embedded metadata stored on IPFS.

What is Cardano?

Cardano is a collection of patent-free, open-source protocols that enable you to store, manage, and transform data and digital identities. Cardano’s developer portal allows users to send and receive native tokens, vote toward community-driven proposals and projects, and interact with smart contracts. Transactions created on the Cardano blockchain can use embedded metadata files, which can be stored on IPFS through Filebase.

Read below to learn how to submit Cardano blockchain transactions with embedded metadata stored on Filebase.

Prerequisites:

In Cardano, the cardano-node communicates with the back-end server, which creates transactions, then queries the blockchain for the transaction’s metadata information for the front-end.

In this guide, we’ll create a transaction metadata file, store it on Filebase, then submit a transaction to the blockchain that uses our metadata file.

1. Create your payment key pair for the transaction:

cardano-cli address key-gen \\
--verification-key-file payment.vkey \\
--signing-key-file payment.skey

2. Create a Cardano wallet if you haven’t previously:

cardano-cli address build \\
--payment-verification-key-file payment.vkey \\
--out-file payment.addr \\
--testnet-magic 1097911063

View your wallet address in the payment.addr file. Take note of this wallet address.

3. Add some test tAda funds using the testnet faucet.

4. Next, create a metadata.json file. Input the following content:

{
"1": {
	"name": "cardano-test metadata",
	"completed": 0
	}
}

5. Next, we’ll upload this file to Filebase.

For this tutorial, we need an IPFS Filebase bucket. For instructions on creating an IPFS bucket, see our documentation here.

This tutorial uses AWS CLI to upload this file. For more information on AWS CLI, see our configuration guide here.

aws --endpoint https://s3.filebase.com s3 cp metadata.json s3://filebase-bucket

6. Once the file has been uploaded to Filebase, we need to retrieve the IPFS CID.

Using AWS CLI, we can get the IPFS CID with the command:

aws --endpoint https://s3.filebase.com s3api head-object --bucket ipfs-bucket-name --key metadata.json

Take note of the Metadata value ‘CID’.

7. Next, query the available UTXO from your wallet address:

cardano-cli query utxo --testnet-magic 1097911063 --address $(cat payment.addr)

Take note of the TxHash value and TxIndex value outputted by this command.

8. Now we’ll submit our transaction to the Cardano blockchain.

Use the following command:

cardano-cli transaction build-raw \\
--tx-in {TxHash}#{TxIndex}\\
--tx-out $(cat payment.addr)+0 \\
--metadata-json-file https://ipfs.filebase.io/ipfs/{IPFS_CID} \\
--fee 0 \\
--out-file tx.draft

Replace the following values:

  • TxHash: TxHash Value from Step 7

  • TxIndex: TxIndex Value from Step 7

  • IPFS_CID: Filebase IPFS CID from Step 6

9. Calculate the transaction fee with the following command:

cardano-cli transaction calculate-min-fee \\
--tx-body-file tx.draft \\
--tx-in-count 1 \\
--tx-out-count 1 \\
--witness-count 1 \\
--byron-witness-count 0 \\
--testnet-magic 1097911063 \\
--protocol-params-file protocol.json

Take note of this value.

10. Rebuild the transaction with the calculated fee:

cardano-cli transaction build-raw \\
--tx-in dfb99f8f103e56a856e04e087255dbaf402f3801acb71a6baf423a1054d3ccd5#0 \\
--tx-out $(cat payment.addr)+1749480133 \\
--metadata-json-file metadata.json \\
--fee [FEE_FROM_STEP_9] \\
--out-file tx.draft

11. Sign the transaction:

cardano-cli transaction sign \\
--tx-body-file tx.draft \\
--signing-key-file payment.skey \\
--testnet-magic 1097911063 \\
--out-file tx.signed

12. Finally, submit the transaction:

cardano-cli transaction submit \\
--tx-file tx.signed \\
--testnet-magic 1097911063

Last updated