This site requires Javascript to be enabled.

Minting and sending tokens

Now that we've got our smart contract deployed we can mint tokens that can be sent to other Archway addresses.

Minting tokens

MintMsg is a message type from the cw721_base package imported by our project's Cargo.toml. It's used by our contract's execution handler to set state for an NFT with metadata corresponding to the TokenInfo modelwe looked at previously.

To mint an NFT, we need to send a transaction to the smart contract with our MintMsg parameters in JSON format. For adding custom traits, we can use the on-chain metadata NFT template and include arbitrary metadata values using the extensions attribute of MintMsg.

This is the JSON string we will use to mint our test NFT:

{  "mint": {    "token_id": "1",    "owner": "archway1f395p0gg67mmfd5zcqvpnp9cxnu0hg6r9hfczq",    "extension": {      "name": "Archway NFT #1",      "description": "Building With NFTs",      "image": "ipfs://QmZdPdZzZum2jQ7jg1ekfeE3LSz1avAaa42G6mfimw9TEn",      "attributes": [        {          "trait_type": "tutorial",          "value": "https://docs.archway.io/developers/guides/nft-project/start"        }      ]    }  }}

To execute our mint transaction we add the JSON arguments using the --args flag of tx command of the Archway Developer CLI.

Developer CLI

archwayd

archway contracts execute basic-nft --args '{"mint":{"token_id":"1","owner":"archway1f395p0gg67mmfd5zcqvpnp9cxnu0hg6r9hfczq","extension":{"name":"Archway NFT #1","description":"Building With NFTs","image":"ipfs://QmZdPdZzZum2jQ7jg1ekfeE3LSz1avAaa42G6mfimw9TEn","attributes":[{"trait_type":"tutorial","value":"https://docs.archway.io/developers/guides/nft-project/start"}]}}}'

To confirm the NFT is now correctly stored on-chain, run the query command, specifying the token_id declared in the minting transaction:

archway contracts query smart basic-nft --args '{"nft_info":{"token_id":"1"}}'# Show output here

The behaviour of the nft_info entrypoint is defined here if you want to read the response model in detail.

Sending tokens

To transfer a token, we have to send a message of the type TransferNft, which we achieve by sending a transaction to the transfer_nft entrypoint exposed by the contract. The params we send to the entrypoint are: the recipient address; and the token_id to be sent to the receiver.

In JSON format, our transaction arguments look like this:

{  "transfer_nft": {    "recipient": "archway1y00hm50lffnxt5m0kuy9afk83gyuye684zwcr5",    "token_id": "1"  }}

Using the Developer CLI, we broadcast the transaction and include the above parameters like this:

developer CLI

archwayd

archway contracts execute basic-nft --args '{"transfer_nft":{"recipient":"archway1y00hm50lffnxt5m0kuy9afk83gyuye684zwcr5","token_id":"1"}}'

Once the transaction is confirmed, ownership of the token will be changed from the address declared as owner at minting (archway1f395p0gg67mmfd5zcqvpnp9cxnu0hg6r9hfczq in this guides's example), to the new receiver address (archway1y00hm50lffnxt5m0kuy9afk83gyuye684zwcr5 in this guides's example). To verify that's the case, we can query the contract again to see who owns the token_id with the value of 1.

archway query contract-state smart --args '{"nft_info":{"token_id":"1"}}'# Show output here

Now that the contract is up and running, read on to learn how to build a dapp around the minting and transfer functionality we just tested.

Drop Camp is here!

Join the queue and be one of the first to get in!.

Go Camping ↗