Nft
ERC 721 未部署為合約
我正在嘗試在 Ropsten 網路上部署我的 ERC-721 合約。部署腳本成功返回了部署合約的地址。但是,當我在 Etherscan 上搜尋該地址時,它顯示為普通地址而不是 Contract。我做錯了什麼?
我正在使用 OpenZepplin 實現和 Hardhat 進行部署。這是我的契約:
pragma solidity ^0.7.3; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract Sakura is ERC721, Ownable { using Counters for Counters.Counter; Counters.Counter private _tokenIds; string public proofFile = ""; // IPFS URL WILL BE ADDED LATER bool public saleIsActive = false; uint public reserve = 125; uint256 public cost = 0.05 ether; constructor() ERC721("Sakura", "SAKURA") {} function mintNFT(address recipient, string memory tokenURI) public onlyOwner returns (uint256) { // require(msg.value >= cost, "Not enough ETH sent: check price."); _tokenIds.increment(); uint256 newItemId = _tokenIds.current(); _mint(recipient, newItemId); _setTokenURI(newItemId, tokenURI); return newItemId; } // function setTokenURIById (uint256 tokenId, string memory tokenURI) public onlyOwner{ // _setTokenURI(tokenId, tokenURI); // } function withdraw() public onlyOwner { uint balance = address(this).balance; msg.sender.transfer(balance); } function tokensOfOwner(address _owner) external view returns(uint256[] memory ) { uint256 tokenCount = balanceOf(_owner); if (tokenCount == 0) { // Return an empty array return new uint256[](0); } else { uint256[] memory result = new uint256[](tokenCount); uint256 index; for (index = 0; index < tokenCount; index++) { result[index] = tokenOfOwnerByIndex(_owner, index); } return result; } } function setProvenanceHash(string memory provenanceHash) public onlyOwner { proofFile = provenanceHash; } function flipSaleState() public onlyOwner { saleIsActive = !saleIsActive; } }
這是部署腳本:
async function main() { // Grab the contract factory const MyNFT = await ethers.getContractFactory("Sakura"); // Start deployment, returning a promise that resolves to a contract object const myNFT = await MyNFT.deploy(); // Instance of the contract console.log("Contract deployed to address:", myNFT.address); } main() .then(() => process.exit(0)) .catch(error => { console.error(error); process.exit(1); });
在錢包地址上呼叫創建合約的函式,這可能需要一些時間,具體取決於網路擁塞、gas 費用等。如果您不斷刷新 Etherscan 頁面,您最終會看到呼叫的合約創建方法,並且地址從普通地址到合約地址。