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 Answers1

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]

Travis Jacobs
  • 1,535
  • 1
  • 13
  • 25
  • 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 Jun 08 '23 at 15:48
  • you can install foundry over and use the commands I mentioned to encode the data. Foundry can be installed here: https://book.getfoundry.sh/getting-started/installation – Travis Jacobs Jun 08 '23 at 16:42