安装openzeppelin智能合约模版
npm install @openzeppelin/contracts
Remix配置
通常remix开发的内容会保存在local storage中,为了安全起见,我们把remix开发的内容存在本地的文件夹中,这样即使rmix挂掉,内容也不会丢失.
Remix本地安装
npm install -g @remix-project/remixd
建立remix和本地文件的关系
remixd -s /path/to/local/dir --remix-ide http://remix.ethereum.org/
开发智能合约
浏览器打开http://remix.ethereum.org , workspace选择localhost
新建智能合约
pragma solidity ^0.8.0;
import "../node_modules/@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol";
contract FCAT is ERC721PresetMinterPauserAutoId {
constructor() public
ERC721PresetMinterPauserAutoId("ColorNFT", "MagicColor", "http://developer.mathwallet.org/bsc/nfttest/#")
{}
// This allows the minter to update the tokenURI after it's been minted.
// To disable this, delete this function.
function setTokenURI(uint256 tokenId, string memory tokenURI) public {
require(hasRole(MINTER_ROLE, _msgSender()), "web3 CLI: must have minter role to update tokenURI");
setTokenURI(tokenId, tokenURI);
}
}
编译智能合约
选择0.8.3版本
发布智能合约
-
准备metamask浏览器钱包
连接测试网rinkeby,记得提前准备测试币.测试币领取地址:faucet.rinkeby.io -
ENVIROMENT
选择inject web3 -
CONTRACT
选择ColorNFT.sol
Mint NFT
合约Deploy之后,在Remix下边找到Mint 按钮,输入我们metamask的钱包地址,点mint,几分钟之后就可以在opensea的测试网看到NFT图片了
打开https://testnets.opensea.io, 用metamask钱包连接.
网友评论