đDeploy and Interact
This section covers deploying the contract, initializing it, and interacting with it on the testnet.
Step 1: Build the Smart Contract
To build the smart contract, use the following command.
When you run the command, you'll see the following:
Note the following:
This build embeds the schema, so you no longer have to keep the schema as a separate compilation output.
Concordium strongly recommends the use of embedded schema.
You should run Docker on your system and let it pull the required image.
Ensure verifiability by including the
--verifiable
flag to verify that the contract source matches the deployed module.You should run Docker on your system and let it pull the required image.
Do not include the Cargo.lock file in .gitignore.
Step 2: Deploy the Contract
Deploy the module using the following command:
When you run the command, you should see the following:
Step 3: Initialize the Contract
Initialize the contract with the specified parameters:
Your contract will be initialized as follows:
Step 4: Mint Tokens
Mint tokens for different states of our pet, each represented by metadata. The metadata and images are publicly available on IPFS for demonstration purposes.
Little Puppy CIS2 Compatible Metadata File
Cool Boy CIS2 Compatible Metadata File
Strong Dog CIS2 Compatible Metadata File
Step 5: Create MintParams JSON File
Create a JSON file for MintParams, including the owner's address and the tokens to be minted. Ensure that it matches the struct defined in the smart contract. Follow these guidelines:
Struct Requirements: Remember the struct you created in the smart contract; it requires an owner and corresponding tokens. Each token entry should hold a list of MetadataUrl for a token ID and its amount.
Metadata Selection: You will include only the first two metadata entries to facilitate addMetadata and upgrade functions testing.
IPFS Upload: Don't forget to upload the metadata files to IPFS. When minting a token, provide a hyperlink to the metadata file and optionally include the SHA(256) hash of the content.
Here's an example JSON file structure:
Step 6: Mint the Token
Mint the token using the created MintParams JSON file and run the following command:
When you run the command, you will see the following in your terminal:
Step 7: Verify Token Minting
After successfully minting the token, verify its presence in your wallet with the following:
Open your Concordium wallet.
Navigate to the section displaying your assets or tokens.
Look for the newly minted token.
Verify that the token appears correctly with the expected metadata and attributes.
The screenshot below shows the wallet:
Step 8: Upgrade Metadata
Test whether this NFT is dynamic or not. You should be able to upgrade the metadata and evolve this little puppy into a grown dog. The
upgrade
function requires the token ID as a string in the JSON file.
Run the following command to upgrade the metadata:
After running the command, you will see the following in your terminal:
The transaction is now complete. Go to the wallet and verify:
Note that an oracle or any other interaction can trigger this step.
Step 9: Add Metadata
Finalize the tutorial by adding new metadata to the contract. Let's make the dog evolve even more.
Check the
AddParams
struct to create the right form of JSON file. It expectstokens
that holds both token ID andMetadataUrl
which is essentiallyurl
andhash
:
Wait for the transaction's finalization as follows:
Upgrade it once again with the same command in the previous step:
Check your wallet to see the change that has been made:
Step 10: View Token Metadata History
To view the history of the token metadata, follow these steps:
Invoke the
tokenMetadataList
function to view it.The
tokenMetadataList
function should accept a vector of token IDs to return:All the tokens in the contract.
The history of the tokens in the form of a
TokenMetadataList
struct, which is defined asVec<Vec<MetadataUrl>>
.
Invoke the
tokenMetadataList
function to view the token's history:
When you run the command, you will be able to see all previous forms of the token you have from the contract state:
Last updated