2

I've developed a very simple smart contract and I'm trying to invoke a function using eth_call. The contract is deployed on the revived Ropsten testnet.

If I invoke the function getSTR() sending the rpc to the local instance of geth I'm able to get back the correct response. The python code is like this:

contractAddress = "0xd02e5779398cd9b05ea7fcd7ed8868524df06313"
urlGeth_rpc = "http://localhost:MYPORT/json_rpc"
functionSignature = "getSTR()"
function_encoded = keccak256_Geth(functionSignature)[:10]

rpc_getSTR = {
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [
        {
            "to": contractAddress,
            "data": function_encoded,
        },
        "latest"
    ],
    "id": "1"
}
response = requests.post(urlGeth_rpc, data=json.dumps(rpc_getSTR), headers=headers)
r = json.loads(json.dumps(response.json()))

When I try to invoke the same function using a remote INFURA node I use this code (practically the same with a different rpc access point)

contractAddress = "0xd02e5779398cd9b05ea7fcd7ed8868524df06313"
urlRopsten_rpc = "https://ropsten.infura.io/MYTOKEN"
functionSignature = "getSTR()"
function_encoded = keccak256_Geth(functionSignature)[:10]

rpc_getSTR = {
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [
        {
            "to": contractAddress,
            "data": function_encoded,
        },
        "latest"
    ],
    "id": "1"
}
response = requests.post(urlRopsten_rpc, data=json.dumps(rpc_getSTR), headers=headers)
r = json.loads(json.dumps(response.json()))

With INFURA the response is <Response [400]>, so something is clearly wrong. I am not able to see the error, maybe is something related to INFURA for which I have to formulate differently the rpc request. I am instead able to use INFURA to call the eth_blockNumber rpc method and get the correct result back.

Thanks for the support

---- UPDATE As requested by in the comment, here is my python code for calling the keccak-256 hash function of the local geth client (which is implemented with the web3_sha3 method)

def keccak256_Geth(string):
    string = "0x" + binascii.hexlify(string)
    rpc_keccak256 = {
        "jsonrpc": "2.0",
        "method": "web3_sha3",
        "params":  [string],
        "id":  "64"
    }

    r = requests.post(rpc_url, data=json.dumps(rpc_keccak256), headers=headers)
    r = json.loads(json.dumps(r.json()))
  • 1
    Could you post your implementation of keccak256_Geth – Maurycy Apr 12 '17 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.