如何修改NFT的元数据

引言

本文针对有一定基础的小伙伴、直接上干货。
背景:昨天接到这么一个需求,在erc721协议铸造后的基础上修改上链后的元数据

参考

在这里插入图片描述

核心源码

    //管理员修改tokenuri
    function setTokenURI(uint256 tokenId, string calldata uri) public onlyOwner {
    
    
        require(_ownerOf(tokenId)!=address(0),"tokenId is error");
        _setTokenURI(tokenId, uri);
    }

    //用户修改tokenuri
    function UserSetTokenURI(uint256 tokenId, string calldata uri) public {
    
    
        require(_ownerOf(tokenId)==msg.sender,"user address is error");
        _setTokenURI(tokenId, uri);
    }

测试

建议上openSea测试网、直接输入你的合约token即可

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_38420688/article/details/141157630