簡體   English   中英

鑄造 nft 后 NFT 合約余額沒有增加

[英]NFT contract balance not increasing after minting nft

我在goerli測試網上部署了一個合約,但我不明白為什么在鑄造 nft 后合約余額沒有增加。

goerli 合約: https://goerli.etherscan.io/address/0x41c13FF48Edc715612763394Ac8D36C4d11b5856

成功的薄荷交易: https://goerli.etherscan.io/tx/0x4a0248639a427b2a824433dce5712d1d86bf85d8a7658d0215aff8cdc9448ea9

    uint256 public constant TOTAL_SUPPLY = 100;
    uint256 public constant MINT_PRICE = 0.02 ether;
    uint256 public constant MAX_PUBLIC_MINT = 10;

    function mintTo(address recipient, uint256 count) public payable {
        uint256 tokenId = currentTokenId.current();
        require(tokenId < TOTAL_SUPPLY, "Max supply reached");
        require(
            count > 0 && count <= MAX_PUBLIC_MINT,
            "Max mint supply reached"
        );

        require(
            msg.value == MINT_PRICE * count,
            "Transaction value did not equal the mint price"
        );

        for (uint256 i = 0; i < count; i++) {
            currentTokenId.increment();
            uint256 newItemId = currentTokenId.current();
            _safeMint(recipient, newItemId);
        }

        bool success = false;
        (success, ) = owner().call{value: msg.value}("");
        require(success, "Failed to send to owner");
    }

我嘗試使用安全帽進行鑄幣:

task("mint", "Mints from the NFT contract")
    .addParam("address", "The address to receive a token")
    .setAction(async function (taskArguments, hre) {
        const contract = await getContract("NftGame", hre);
        const transactionResponse = await contract.mintTo(taskArguments.address, 1, {
            gasLimit: 500_000,
            value: ethers.utils.parseEther(String(0.02 * 1))
        });
        console.log(`Transaction Hash: ${transactionResponse.hash}`);
    });

應該增加什么余額? 向我們展示整個合同。

  • 如果您指的是鑄造到某個地址的 NFT 余額,請檢查balanceOf(address)方法。
  • 但我認為“鑄造 nft 后合約余額不會增加”是指調用mintTo后合約的以太幣余額不會增加。 這背后的原因可以在(success, ) = owner().call{value: msg.value}("");行中找到。 . 調用mintTo時發送的帶有 tx 的以太幣被發送給合約的所有者。 由於這個原因,合約的以太幣余額不會增加,但合約所有者的以太幣余額應該會增加msg.value Look at the tx you provided, it says "TRANSFER 0.02 Ether From 0x41c13ff48edc715612763394ac8d36c4d11b5856 To 0x6c3455607f5592612e9e3754ba37c63123d68722" where 0x41c13ff48edc715612763394ac8d36c4d11b5856 is the address of the contract and 0x6c3455607f5592612e9e3754ba37c63123d68722 is the address of the owner of the contract.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM