0

I am trying to run the smart contract listed in the documentation here https://docs.soliditylang.org/en/v0.8.7/introduction-to-smart-contracts.html#subcurrency-example

    // Sends an amount of newly created coins to an address
    // Can only be called by the contract creator
    function mint(address receiver, uint amount) public {
        require(msg.sender == minter);
        balances[receiver] += amount;
    }

But every time I try to execute the mint function, it fails with the following error:

transact to Coin.mint errored: Error encoding arguments: Error: invalid address (argument="address", value="1000000", code=INVALID_ARGUMENT, version=address/5.4.0) (argument=null, value="1000000", code=INVALID_ARGUMENT, version=abi/5.4.0)

I am using the Remix IDE integrated with my MetaMask.

Any idea why and how to fix it?

4
  • What are u giving as input ? That function take 2 arguments
    – Majd TL
    Sep 25, 2021 at 17:45
  • i am passing a number to the mint function via the remix UI Sep 26, 2021 at 0:44
  • you need to pass 2 arguments. this function take 2 , first the address and then the amount of tokens
    – Majd TL
    Sep 26, 2021 at 8:00
  • F5 - update your navigator, maybe REMIX is taken a cached ABI instead the last compiled
    – JTCon
    May 11, 2022 at 16:35

2 Answers 2

2

As per the error message and logs it looks like you're passing invalid arguments ---

(argument="address", value="1000000", code=INVALID_ARGUMENT, version=address/5.4.0)

The address argument expects an address type argument, but you're passing a number (1000000) instead.

(argument=null, value="1000000", code=INVALID_ARGUMENT, version=abi/5.4.0)

The second parameter should have had an argument type "amount" but it appears to be null.

Looks like you need to double-check the parameter-argument pairs that you're passing.

0

This happened to me while trying to pass an address type argument in mocha tests with value of null, the solution was to set the value to 0x0000000000000000000000000000000000000000, which is the equivalent of address(0) in solidity.

So from this

  contract.mint({
    id: 0,
    name: 'Luger',
    kind: 'weapon',
    price: 1,
    owner: null
  })

To this

  contract.mint({
    id: 0, // temporary
    name: 'Luger',
    kind: 'weapon',
    price: 1,
    owner: '0x0000000000000000000000000000000000000000'
  })

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.