将 erc721 拥有的智能合约部署到安全帽 localhost

Deploying an erc721 ownable smart contract to hardhats localhost

提问人:Jacob 提问时间:11/15/2023 最后编辑:Jacob 更新时间:11/15/2023 访问量:45

问:

建立了一个 ERC721 合约,将每个用户的铸币厂限制为 3 个,具有最大供应量和铸币厂价格。我希望将合约部署到 Sepolias 测试网络,但 Ownable 合约有问题:


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract Landscape is ERC721, ERC721URIStorage, ERC721Pausable, Ownable {

    uint256 public mintPrice; 
    uint256 public totalSupply;
    address public owner_;
    uint256 public maxSupply;
    uint256 public maxPerWallet;
    bool public isPublicMintEnabled;
    mapping(address => uint256) public walletMints;



    constructor(address initialOwner) ERC721("Landscape", "LSC") Ownable(initialOwner) {
        owner_ = initialOwner;
        mintPrice = 0.014 ether; 
        totalSupply = 0; 
        maxPerWallet = 3; 
        maxSupply = 221;
    }

    function _baseURI() internal pure override returns (string memory) {
        return "ipfs://QmS9xeVShu1ixwApExG5tAJYMpnzzd5oGhxdTUuov5u73w/";
    }

    function balanceOf()  public view returns(uint){
        return address(this).balance;
    }

    // WITHDRAW FUNDS
      function withdraw() external payable onlyOwner {
        payable(owner()).transfer(address(this).balance);
    }

    function pause() public onlyOwner {
        _pause();
    }

    function unpause() public onlyOwner {
        _unpause();
    }

    function setIsPublicMintEnabled(bool _isPublicMintEnabled) external onlyOwner {
        isPublicMintEnabled = _isPublicMintEnabled;
    }

    function safeMint(uint256 quantity_)
        public
        payable
    {
        require(isPublicMintEnabled, "Mint not currently available");
        require (msg.value == quantity_ * mintPrice, "wrong mint value!");
        require(walletMints[msg.sender] + quantity_ <= maxPerWallet, "Mint Limit is 3"); 
        require(totalSupply + quantity_ <= maxSupply, "SOLD OUT");

        for(uint256 i = 0; i < quantity_; i++){
            uint256 newTokenId = totalSupply + 1;
            totalSupply++;
            _safeMint(msg.sender, newTokenId);
        }
    }

    // The following functions are overrides required by Solidity.

    function _update(address to, uint256 tokenId, address auth)
        internal
        override(ERC721, ERC721Pausable)
        returns (address)
    {
        return super._update(to, tokenId, auth);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

我不确定如何部署合约,因为我不知道如何在部署脚本中为构造函数参数分配初始所有者:

const hre = require("hardhat");

async function main() {
  console.log("Hello!")  
  const {deployer} = await ethers.getSigner();
  const Landscape = await hre.ethers.getContractFactory("Landscape");
  console.log("Deploying...")
  const landscape_ = await Landscape.deploy(deployer);
  console.log("HEY")
  await landscape_.waitForDeployment()

  Address = await landscape_.getAddress()
  console.log("Deployed to:", Address)
}

main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

如何获取 initialAddress 的有效地址,以便部署到 Sepolias 网络?

我试过输入我正在使用的钱包地址,这适用于 localhost 网络:

const hre = require("hardhat");

async function main() {
  console.log("Hello!")  
  const Landscape = await hre.ethers.getContractFactory("Landscape");
  console.log("Deploying...")
  const landscape_ = await Landscape.deploy("*wallet_address*");
  console.log("HEY")
  await landscape_.waitForDeployment()

  Address = await landscape_.getAddress()
  console.log("Deployed to:", Address)
}


main().catch((error) => {
    console.error(error);
    process.exitCode = 1;
});

但是当我尝试在 Sepolia 上部署时,我得到:

Hello!
Deploying...
Error: factory runner does not support sending transactions (operation="sendTransaction", code=UNSUPPORTED_OPERATION, version=6.8.1)
    at makeError (/Users/macbook/nft-ls-app/node_modules/ethers/src.ts/utils/errors.ts:694:21)
    at assert (/Users/macbook/nft-ls-app/node_modules/ethers/src.ts/utils/errors.ts:715:25)
    at ContractFactory.deploy (/Users/macbook/nft-ls-app/node_modules/ethers/src.ts/contract/factory.ts:107:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at main (/Users/macbook/nft-ls-app/scripts/deploy.js:13:22) {
  code: 'UNSUPPORTED_OPERATION',
  operation: 'sendTransaction',
  shortMessage: 'factory runner does not support sending transactions'
}

我猜交易是将该钱包地址分配为初始所有者的过程,但我该如何解决这个问题?任何帮助都会很棒!

以太坊 安全帽 ERC721

评论


答: 暂无答案