0

I'm trying to query this contract: 0x992678ad242230Dd795107Fee8B572E27083002A and to get the "getglobalStakedTokensPerPeriod" (number 11) with the unit456 of 1 (period 1)

I've tried to use this api: https://api.etherscan.io/api ?module=proxy &action=eth_call &to=0x992678ad242230Dd795107Fee8B572E27083002A &data=?? &tag=latest &apikey=YourApiKeyToken

but didn't understand what to put in the "data=" part

I saw this question but still couldn't get it to work using the solution that was provided: How to query a uint256 input contract function via Etherscan's API?

1 Answer 1

0

Etherscan expects encoded calldata as the data argument (docs).

You can get this multiple ways, including using ethers.js (look at the interface.encodeFunctionData section), or with cast calldata from foundry.

For your example, using cast we can do:

$ cast calldata "getglobalStakedTokensPerPeriod(uint256)(uint256)" 11

0x2d9ba1cd000000000000000000000000000000000000000000000000000000000000000b

We can then pass this to the etherscan API call, and get back something like this:

0x00000000000000000000000000000000000000000000000000080e050bced973

Then we need to decode, again according to the function ABI:

$ cast --abi-decode "getglobalStakedTokensPerPeriod(uint256)(uint256)" 0x00000000000000000000000000000000000000000000000000080e050bced973

2267214649416051 [2.267e15]
2
  • thank you for the reply, I really don't have experience in code, so to make this convert in to encoded data where to I go and use the method you mentioned?
    – Harel Leon
    Commented Jun 8, 2023 at 15:48
  • you can install foundry over and use the commands I mentioned to encode the data. Foundry can be installed here: book.getfoundry.sh/getting-started/installation Commented Jun 8, 2023 at 16:42

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.