简体   繁体   English

铸造 nft 后 NFT 合约余额没有增加

[英]NFT contract balance not increasing after minting nft

I have a contract deployed on goerli testnet but I don't understand why the contract balance doesn't increase after minting an nft.我在goerli测试网上部署了一个合约,但我不明白为什么在铸造 nft 后合约余额没有增加。

Contract on goerli: https://goerli.etherscan.io/address/0x41c13FF48Edc715612763394Ac8D36C4d11b5856 goerli 合约: https://goerli.etherscan.io/address/0x41c13FF48Edc715612763394Ac8D36C4d11b5856

Succesful mint transaction: https://goerli.etherscan.io/tx/0x4a0248639a427b2a824433dce5712d1d86bf85d8a7658d0215aff8cdc9448ea9成功的薄荷交易: 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");
    }

I tried minting using hardhat:我尝试使用安全帽进行铸币:

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}`);
    });

What balance should be incremented?应该增加什么余额? Show us the entire contract.向我们展示整个合同。

  • If you mean the balance of the NFTs minted to some address, check the balanceOf(address) method.如果您指的是铸造到某个地址的 NFT 余额,请检查balanceOf(address)方法。
  • But I think by "contract balance doesn't increase after minting an nft" you mean the ether balance of the contract does not increase after calling mintTo .但我认为“铸造 nft 后合约余额不会增加”是指调用mintTo后合约的以太币余额不会增加。 The reason behind this can be found in line (success, ) = owner().call{value: msg.value}("");这背后的原因可以在(success, ) = owner().call{value: msg.value}("");行中找到。 . . The ether send with a tx when calling mintTo is sent to the owner of the contract.调用mintTo时发送的带有 tx 的以太币被发送给合约的所有者。 For this reason, the ether balance of the contract does not increase, but the ether balance of the contract owner should increase by msg.value .由于这个原因,合约的以太币余额不会增加,但合约所有者的以太币余额应该会增加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. 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