[SOLVED] EVM web3 API v2: {address}/function query with "" input's name

curl -X 'POST' \
  'https://deep-index.moralis.io/api/v2/0x45c54210128a065de780C4B0Df3d16664f7f859e/function?chain=bsc&function_name=userInfo' \
  -H 'accept: application/json' \
  -H 'X-API-' \
  -H 'Content-Type: application/json' \
  -d '{
  "abi": [{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"},{"internalType":"contract IMasterChefV2","name":"_masterchefV2","type":"address"},
__many other things__
{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userInfo","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"},
{"internalType":"uint256","name":"lastDepositedTime","type":"uint256"},{"internalType":"uint256","name":"cakeAtLastUserAction","type":"uint256"},{"internalType":"uint256","name":"lastUserActionTime","type":"uint256"},{"internalType":"uint256","name":"lockStartTime","type":"uint256"},{"internalType":"uint256","name":"lockEndTime","type":"uint256"},{"internalType":"uint256","name":"userBoostedShare","type":"uint256"},{"internalType":"bool","name":"locked","type":"bool"},{"internalType":"uint256","name":"lockedAmount","type":"uint256"}],"stateMutability":"view","type":"function"},
__many other things__
],
  "params": { "address": "0xF2c71B372a6e374C57B86de5c9f691f138cbeEb5" }
}'

Results in:

Error: response status is 400

Response body
{
  "message": " is required"
}

What am I doing wrong?
I already tried adding/removing square brackets, removing “params” or “address”, without success…

Same inputs on Bscscan.com gives correct results so I guess is just a matter of syntax.

Thank you :pray:t2:

Nope but thanks…

The problem was in the name of the input: I could see from the ABI the input name for the userInfo function is “” (that is: empty instead of “address”, LOL?), so I could make it work like this:

“abi”: […],
“params”: { “”: “0x…” }

You can also change the name in the ABI and then reference this name as the parameter.

{"inputs":[{"internalType":"address","name":"changed","type":"address"}

...

params: {
  changed: ""
}

You will need to do this if there are multiple unnamed inputs.

How to send the values for unnamed inputs though!? I don’t want to change the original contract ABI!

If I manually change the inputs’ names I can achieve the desired result easily, like this:

request body:
{
“abi”: […],
“params”: {“custom1”:“0”,“custom2”:“0x…”}
}

Can you do that with “” instead of “custom1” and “custom2”??

Yes you can use "", but you can only do it with one input.

1 Like

Then is this a “bug” that can be solved by Moralis, or it is inherent in the json syntax and the contract ABI (having unnamed inputs)?

I’m not sure why some ABIs/contracts don’t use names for particular functions. But there’d be no way to associate more than one "" with a particular input. There’s nothing wrong with changing the ABI locally.