0

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 contracts 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

1 Answer 1

0

Seems that you're passing the values just right but I think that you need to pass a 0 to the getSigner function

const signer = provider.getSigner(0);
1
  • 1
    Thanks for the feedback, I just figured out that the address needs to be converted to a string before passing in javascript. My function is working now :)
    – Damon
    Commented Aug 12, 2022 at 16:13

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.