Calling a contract method from RPC

The JSON-RPC API doc for eth_call does not describe how you can call a specific constant method on a contract which returns arbitrary data. Are there any examples for this? In this case I know the source code of the contract - would it also be possible without knowing it?

Comments

  • TonyBTonyB Member Posts: 4
    Void poses an excellent question in this post, but the answer seems obscure and non-trivial; in contrast to typical web applications where an HTTP transaction can call a Java class named "greeter.class" using syntax like: http://mydomain.com/greeter.class?HelloToYou. With Ethereum JSON-RPC, it appears that several more steps are required to call a method of a custom built contract. Eris Industries has an Eris by Curl tutorial page that lists the following eight steps to call a contract using JSON-RPC:

    Step 1 - Start a chain
    Step 2 - Compile Solidity Contract
    Step 3 - Create and Sign Transaction for Deploying Contract
    Step 4 - Broadcast tx to the blockchain
    Step 5 - Wait for a confirmation
    Step 6 - Verify the contract's bytecode
    Step 7 - Create and Sign Transaction for Talking to Contract
    Step 8 - Talk to Contracts Without Creating Transactions

    That's a bunch of steps to simply invoke a method on a contract. Why so many?

    Calling methods built into the JSON-RPC API and retrieving results seems straightforward. For instance, obtaining the Ethereum client name and version can be done with:

    curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' localhost:8545
    {"id":67,"jsonrpc":"2.0","result":"Geth/v1.3.5-34b622a2/linux/go1.6"}

    I know there's lots more happening under the covers with blockchain compared to a simple web application. It would be neat to see the JSON-RPC documentation updated to include more examples and simple examples that illustrate how to get started.
Sign In or Register to comment.