ERC721铸造NFT / 学习智能合约#55

in hive-180932 •  3 years ago 

目前市场上流行的NFT标准是ERC721,而这个标准和ERC20类似,都有一些标准的函数和库。并且,一般只要按照OpenZeppelin的标准来就行。比如今天要铸造的NFT就可以直接引用OpenZeppelin的库,自己要写的方法估计也就不到10行。直接来看下:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../access/Ownable.sol";   //OpenZeppelin
import "../erc721/ERC721URIStorage.sol";

contract LarkArt is ERC721URIStorage, Ownable {
    uint256 public id;

    constructor() ERC721("LarkArtGallery", "LAG"){
        id = 0;
    }

    function createArtNFT (string memory _tokenURI) external returns (uint256){
        uint256 tokenId = id;
        _safeMint(msg.sender, tokenId);
        _setTokenURI(tokenId, _tokenURI);

        id ++;

        return tokenId;
    }
}

如上所示,铸造NFT只需要这短短十来行代码即可!铸造完成后,OpenSea会自动索引,你只需挂出售卖即可,相当便利。

基于这样的合约方法,我开发了一个NFT平台: https://ilark.io , 有兴趣的朋友可以试着玩下。

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!