How do I pass arguments to a mint function for the ERC155 smart contract?

413 views Asked by At

I am trying to write a handleMint() function in my React app using Ethers.js. My smart contract uses the ERC1155 standard. I'm having trouble writing the handleMint() function so that it passes the necessary arguments to my smart contract's mint function. Here is my handleMint() function is js:

async function handleMint1() {
    console.log(props.accounts)
    if (window.ethereum) {
      const provider = new ethers.providers.Web3Provider(window.ethereum);
      const signer = provider.getSigner();
      const contract = new ethers.Contract(
        charlesWhitsteenProjectAddress,
        charlesWhitsteenProjectNFT.abi,
        signer
      );
      try {
        const response = await contract.mint(props.accounts, BigNumber.from('1'), BigNumber.from(mintAmount1), {
          value: ethers.utils.parseEther((0.01 * mintAmount1).toString())
        });
        console.log('response: ', response);
      } catch (err) {
        console.log('error: ', err)
      }
    }
  }

props.accounts is passing in the address of the connected wallet. BigNumber.from('1') is supposed to be the token ID, and the BigNumber.from(mintAmount1) is supposed to be the amount of tokens to mint.

Here is my mint function in Solidity:

function mint(address _recipient, uint256 _tokenId, uint256 _amount) public payable {

        if(whitelistedAddresses[msg.sender] == 0) {
            require(mintEnabled, "Minting has not been enabled.");
            require(msg.value == _amount * mintPrice, "Incorrect mint value.");
        } else {
            require(whitelistGiveaway, "Whitelist giveaway has not been enabled");
            require(isValid(_tokenId) == true, "Whitelist giveaway is no longer valid.");
            whitelistedAddresses[msg.sender] -= _amount;
        }

        require(_amount >= 1, "please enter a valid number");
        require(totalSupply[_tokenId] + _amount <= maxSupply, "Sorry, you have exceeded the supply.");
        require(tokenIdMints[msg.sender][_tokenId] + _amount <= maxPerTokenId, "Sorry, you have exceeded the alotted amount per token ID.");

        totalSupply[_tokenId] += _amount;
        tokenIdMints[msg.sender][_tokenId] += _amount;
        _mint(_recipient, _tokenId, _amount, "");
        
    }

And finally, here is the error message I'm getting in my console when I click the Mint button in my app:

error:  Error: invalid address or ENS name (argument="name", value=["0x.."], code=INVALID_ARGUMENT, version=contracts/5.6.2)

It looks like the problem, at this point is the address (props.accounts). Can anyone tell me how I can properly pass arguments to my mint function?

0

There are 0 answers