简体   繁体   中英

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.

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

Succesful mint transaction: 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.
  • 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 . The reason behind this can be found in line (success, ) = owner().call{value: msg.value}(""); . The ether send with a tx when calling mintTo is sent to the owner of the contract. 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM