1

I have a payable nft mint contract that send ETH fee to owner, when calling mint() function I recieve

Error function_selector = 0x, data = 0x

tx -> https://goerli.explorer.zksync.io/tx/0x050aefbe633a218fcab3783d70ace7ac93be6c04db19ac70327216a62d1f0a03

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

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract TreeToken is ERC721URIStorage {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    // address for payment
    address payable public owner;
    // supply
    uint256 public supply;
        // mint start date
    uint256 public startMintDate;

    constructor(uint256 _supplyLimit, address owner_, uint256 _startMintDate) ERC721("TreeToken", "TREE") {
        supply = _supplyLimit;
        startMintDate = _startMintDate;
        owner = payable(owner_);
    }

    function mint() public payable returns (uint256) {
        // check price
        require(msg.value ==  0.001 ether, "Payment must be 0.001 ether");
        // check supply
        require(_tokenIds.current() < supply, "Supply limit reached");
        // check start date
        require(block.timestamp >= startMintDate, "Minting is not yet allowed");
        
        _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(msg.sender, newItemId);
        owner.transfer(msg.value);
        return newItemId;
    }

}

after I saw this I am pretty confused and do not know what to do.

1 Answer 1

1
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract TreeToken is ERC721URIStorage {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    // address for payment
    address payable public owner;
    // supply
    uint256 private  supply;
        // mint start date
    uint256 private startMintDate;

    constructor(uint256 _supplyLimit, address owner_, uint256 _startMintDate) ERC721("TreeToken", "TREE") {
        supply = _supplyLimit;
        startMintDate = _startMintDate;
        owner = payable(owner_);
    }

    // mint function for 1 eth payment goes to owner, cannot more than supply

    function mint() public payable returns (uint256) {
        // check price
        require(msg.value == 1 ether, "Payment must be 1 ether");
        // check supply
        require(_tokenIds.current() < supply, "Supply limit reached");
        // check start date
        require(block.timestamp >= startMintDate, "Minting is not yet allowed");
       
        (bool success, ) = owner.call{value: msg.value}("");
        
        // Check if the call was successful
        require(success, "Ether transfer failed");        
         _tokenIds.increment();
        uint256 newItemId = _tokenIds.current();
        _mint(msg.sender, newItemId);
        return newItemId;
    }

}

Using low level call worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.