0

I haven't worked with web3.js in two years, and back then I didn't have any of these issues. Now I keep running into this error when calling a contract function that takes an address and a uint256 to return an object I use to populate a table on the front end:

Error: Uncaught (in promise) o: Web3 validator found 1 error[s]: value "0" at "/1" must pass "address" validation at u.validate (https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js:2:601874) at t.Web3Validator.validate (https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js:2:603466) at Object. (https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js:2:430532) at PopulateStakeTable (http://192.168.0.17:3000/js/tokenstake.js:117:53)

The function works fine when I interact with the contract on Polygonscan passing and address and 0 as the values. Examplpe using the contract

From the ABI: {"inputs":[ {"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}], "name":"yourStakes", "outputs":[{"internalType":"uint40","name":"stakeId","type":"uint40"},...

The JavaScript

for(var i = 0; i < stakeCount; i++){ var stake = await rewardsContract.methods.yourStakes(activeAccount, i).call(); ...}

I console log that the activeAccount is correctly passing to the call, but I don't understand why it is saying the value 0 must pass address validation when the contract function expects uint256.

Any idea what I'm doing wrong?

1
  • I have seen the same error when I passed web3.eth.accounts.wallet[i] instead of address itself.
    – MortezaE
    Commented Aug 12 at 21:18

1 Answer 1

0

I suspect this might be an issue in the web3.js library, potentially related to overloaded functions. I just commented out the following piece of code in the _createContractMethod function, and the method call works as expected.

//validator.validate(abi.inputs ?? [], abiParams);

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.