Our blog

5 Minutes Lesson: What is Dynamic NFT and Its Possibilities

Blockchain

FOREWORD

Since last year, the term NFT has been spreading worldwide, and related technological applications have also made it a hot topic among enterprises. Unlike traditional NFT, dynamic NFT, as a branch that has recently received more attention, can contain interactive and changeable elements, bringing more innovation and value applications.

What is Dynamic NFT (dNFT)

First, the biggest advantage of dynamic NFT is like its name - high variability and scalability. It can present more elements than static NFTs, such as animations, sounds, interactive images, etc., and produce metadata changes over time or conditions. For example, a dynamic NFT artwork can present different styles or express other emotions at different points in time; a dynamic NFT game prop can be upgraded with progress, improving the interactivity and playability of the game.
This is mainly due to its acceptance of data. You can change the attributes of your NFT through “on-chain data” or “off-chain data”. Among them, the former can be directly accessed through the smart contract, and the latter needs to be captured online through Oracle and then added to the blockchain.

How to build your own dNFTs

Writing dynamic NFT requires certain technical knowledge and professional skills, so the following will help you prepare for the project based on the basic construction steps.

Step 1: Determine Your Design

First, you need to determine your NFT design. Please note that this not only refers to your NFT image but covers all plans of this project (white paper, roadmap, etc.), because this will directly affect the future changes of dNFT and the writing of smart contracts. For example, your dNFT can be artwork, game props, musical works, physical asset bindings, etc. You need to consider the changeability and interactivity of elements, and how they can provide more value and experience for the holder.

Step 2: Choose your blockchain

Next, you need to choose the public chain you want to publish. As Ethereum, BNB Smart Chain, Polygon, etc., these platforms all support creating and issuing of dynamic NFT. Note, however, your chosen chain will directly affect the programming language used to write your smart contracts.

Step 3: Write smart contracts

Writing smart contracts is a critical step in creating dynamic NFTs. You need to use Solidity or other programming languages ​​that support NFT creation (e.g. Rust, Vyper, and Move) to develop smart contracts. This contract will combine Metadata to define NFT attributes and images. When creating a dynamic NFT, you need to determine how and how often the dynamic elements will change, and how they will interact with the smart contract after deployment.
Let’s see one of the simple dNFT codes:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract DynamicNFT is ERC721URIStorage {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIds;

    constructor() ERC721("DynamicNFT", "DNFT") {}

    struct NftMetadata {
        string name;
        string description;
        string image;
        uint256 price;
        uint256[] dynamicAttributes;
    }

    mapping(uint256 => NftMetadata) private _nftMetadata;

    function createNft(
        address recipient,
        string memory tokenURI,
        string memory name,
        string memory description,
        string memory image,
        uint256 price,
        uint256[] memory dynamicAttributes
    ) public {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();

        _mint(recipient, newItemId);
        _setTokenURI(newItemId, tokenURI);

        _nftMetadata[newItemId] = NftMetadata(
            name,
            description,
            image,
            price,
            dynamicAttributes
        );

        emit NftCreated(
            newItemId,
            recipient,
            tokenURI,
            name,
            description,
            image,
            price,
            dynamicAttributes
        );
    }

    function getNftMetadata(uint256 tokenId)
        public
        view
        returns (NftMetadata memory)
    {
        require(
            _exists(tokenId),
            "DynamicNFT: metadata query for nonexistent token"
        );

        return _nftMetadata[tokenId];
    }

    function updateDynamicAttribute(
        uint256 tokenId,
        uint256 attributeIndex,
        uint256 newValue
    ) public {
        require(
            _exists(tokenId),
            "DynamicNFT: attribute update for nonexistent token"
        );

        NftMetadata storage metadata = _nftMetadata[tokenId];

        require(
            attributeIndex < metadata.dynamicAttributes.length,
            "DynamicNFT: invalid attribute index"
        );

        uint256 oldValue = metadata.dynamicAttributes[attributeIndex];

        metadata.dynamicAttributes[attributeIndex] = newValue;

        emit NftAttributeUpdated(tokenId, attributeIndex, oldValue, newValue);
    }

    event NftCreated(
        uint256 newItemId,
        address recipient,
        string tokenURI,
        string name,
        string description,
        string image,
        uint256 price,
        uint256[] dynamicAttributes
    );

    event NftAttributeUpdated(
        uint256 tokenId,
        uint256 attributeIndex,
        uint256 oldValue,
        uint256 newValue
    );
}

//This code is for educational purposes only, please do not invest in any assets.

Step 4: Write the front-end interface

Once your smart contract is written, you need to write the front-end interface (a Dapp that can connect to the wallet) so that users can interact with the NFT. You can use frameworks like Web3.js to write front-end interfaces, which can interact with blockchains like Ethereum to realize NFT sales, transfers and trigger change conditions.

Step 5: Test and Release

Finally, you need to test the dynamic NFT, make sure it is functional, and issue it on the blockchain. After that, you can conduct a primary sale on the platform (established in step 4) or directly list the NFT to an existing secondary market, such as OpenSea, Rarible, etc., for sale or auction.

Conclusion

All in all, dNFT is a relatively new type of NFT, which can provide a richer experience and more application scenarios. To create a dNFT, you need to write specialized smart contracts to define and update dynamic properties. In addition, dNFT will become increasingly popular and create more opportunities for artists, game developers, collectors, etc.
If you are looking for a professional dNFT developer, you are welcome to contact our blockchain experts.