NEW

Introducing Transporter, a new bridging app powered by CCIP. Go cross-chain.

Back

Dynamic Metadata with Automation

Use Chainlink Automation to create NFTs that can change over time, based on user interaction, or any number of conditions.

Video

Learn how to create dynamic NFTs by following along with this video tutorial:

Objective

In this tutorial, you will use the Chainlink Automation Network to help create a dynamic NFT by using the Automation-compatible smart contract provided in the repository.

The demo includes:

  • Setting up and funding an upkeep on the Chainlink Automation Network
  • Setting up a dynamic NFT and viewing the progression of the NFT on OpenSea.

You can use this example as a starting point for building your own dynamic NFTs and provide more interactive experiences with your collections.

Before you begin

Before you start this tutorial, complete the following items:

  • If you are new to smart contract development, learn how to Deploy Your First Smart Contract.
  • Set up a cryptocurrency wallet
  • To deploy this contract on testnets, ensure the deployer account has testnet LINK. Use the LINK faucet to retrieve testnet LINK.
  • Open a new Remix project.

Steps to implement

1 Compile and deploy your contract
  1. Open the 2_complete.sol contract in Remix and rename the contract to dynNFT.sol.

  2. Compile the contract in Remix. Under the section titles DEPLOY & RUN TRANSACTIONS you will have to change some values in the dropdown menus. Under ENVIRONMENT, select Injected Provider - MetaMask or WalletConnect depending on the cryptocurrency wallet you are using. Selecting one of these options will prompt you to connect your wallet with Remix.

    Dynamic Metadata Quickstart Step 2
  3. Ensure that the CONTRACT field displays dynNFT. Finally, for the Deploy value, you must enter a time interval value denoting when the dynamic NFT will change. For this demo, we have inputted 30, but you can change this value. Once you have entered your interval, click the orange Deploy button and follow the prompts to allow the transaction to be performed. This may take a few minutes depending on factors such as network traffic.

2 Mint an NFT
  1. Once the contract is deployed, you should be able to see more information under the Deployed Contracts section.

    At this point, you can mint an NFT. In the field next to safeMint paste your wallet address. Then, click the orange transact button and follow the prompts to confirm the transaction.

    Dynamic Metadata Quickstart Step 4
  2. After minting the NFT, you can look at the stage of the NFT based on the tokenURIs given in the contract. Enter "0" in the flowerStage field and click the blue call button. You should see the stage of the NFT.

    Enter 0 in the tokenURI field and click the blue call button to see the corresponding URI for the NFT.

    Dynamic Metadata Quickstart Step 5.1 Dynamic Metadata Quickstart Step 5.2
3 Register an upkeep
  1. Copy the contract address and open the Chainlink Automation Interface. Connect your wallet to the network and click the blue button Register New Upkeep. For the Trigger mechanism, select Custom logic. You will prompted to enter your contract address. Paste your address and click Next.

    Dynamic Metadata Quickstart Step 6
  2. You must fill out the prompts to finish registering upkeep. For the Starting balance (LINK), enter 0.5 for this demo. After entering information, click Register Upkeep. It may take a few moments for this to complete.

4 Trigger the upkeep
  1. Navigate back to Remix. Under the Deployed Contracts section, enter [] in the checkUpkeep field and click the blue button. You may see the following text: upkeepNeeded true. This means that an upkeep will be performed.

    Dynamic Metadata Quickstart Step 8
  2. While waiting for the upkeep to be performed, copy the contract address to your clipboard and open OpenSea (https://testnets.opensea.io/). Paste your address in search bar at the top of the page. You should be directed to a page with the image of your minted NFT. Click the seed thumbnail to learn more about the NFT.

    Dynamic Metadata Quickstart Step 9
  3. Navigate back to Remix. Enter [] in the checkUpkeep field and click the blue button. If this returns upkeepNeeded false your upkeep should have been performed. Navigate to the Chainlink Automation Interface and select your upkeep to view more details and to confirm that an upkeep was performed. If upkeepNeeded false is not returned in Remix, you may have to wait a few minutes and run the checkUpkeep function.

    Dynamic Metadata Quickstart Step 10
5 Check the NFT stage
  1. Once the upkeep has been performed, navigate to Remix and click flowerStage and tokenURI to see the most recent flower stage and corresponding URI. Navigate back to the information of your NFT on OpenSea. Click the button on the top right to refresh the metadata. You should see the NFT become a bloom.

    Dynamic Metadata Quickstart Step 11
  2. To see the NFT become a fully blossomed flower, you will have to wait another 30 seconds (or the amount of time you denoted when deploying your contract). After this interval, refresh the NFT's metadata again. You should see a fully blossomed flower. You have now completed the tutorial.

    Dynamic Metadata Quickstart Step 12

Summary

This tutorial used Chainlink Automation to create a dynamic NFT. This was done by deploying an Automation compatible contract in Remix and registering an Upkeep with the Chainlink Automation network. The NFT changed every 30 seconds based on the time interval we inputted when deploying the contract. The final NFT stage was a fully bloomed flower.

Stay updated on the latest Chainlink news