[Ethereum] Trying to use eth_call to contract function which takes an address as it’s argument

json-rpc

I'm trying to call a function on my smart contract that's deployed on the main Ethereum network.

The function signature is balanceOf(address).

So far I've followed the instructions of doing the SHA3 hash of this so I get: 0x70a08231.

Now I want to send the address there, in the instructions it says to pad the parameters to 32 bytes. As I understand it, Ethereum addresses are 20 bytes like so: 0x4Ef58B0097A47fb07e9e10e4da92ed27DF36aFFF. Does this mean I should do something like 0000000000000000000000004Ef58B0097A47fb07e9e10e4da92ed27DF36aFFF?

Could someone help me to create the 'params' part for a eth_call. I've followed this tutorial here: How to call a contract method using the eth_call JSON-RPC API. And I understand how to do it if the parameters were an int for example. But how to do it for the address above?

An ideal answer would show the data that I need to send and explain the steps 🙂

So far I have the data part as this:

[{"to": "0x722180f08646A73f744f33eD66fD3C990DC6a78B", "data": "0x70a08231000000000000000000000000E676c814EaD2Ae27f706fC3067015a75eb4A94A5"}]

The error I currently get is "Invalid method parameters – missing value for required argument 1".

Thanks

Best Answer

You forgot the 2nd argument. The request should look like this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_call",
  "params": [
    {
      "to": "0x583cbbb8a8443b38abcc0c956bece47340ea1367",
      "data": "0xbeabacc80000000000000000000000008a7784D22eeD131953D0B95f32Adf092A0C0A571000000000000000000000000145e99f7bc840f3ea42d9a64221f041f9955dca2",
      "from":"0x8a7784D22eeD131953D0B95f32Adf092A0C0A571"
    },
    "latest"
  ]
}

Notice the latest argument.

Related Topic