Ethereum is a decentralized platform for applications that run exactly as programmed without any chance of fraud, censorship or third-party interference (https://www.ethereum.org/).
JSON RPC is a remote procedure call protocol and the API is used to help integrate with Ethereum.
One advantage of using the JSON RPC API is the simplicity of storing the Ethereum blockchain ledger. The Ethereum blockchain ledger is more than 400GB in size. It is difficult to store the ledger in normal devices. Using the JSON RPC API, one device can store the whole ledger and others can use the stored blockchain ledger without keeping their own ledger.
After enabling JSON RPC, the node acts as a server. Because of that It's easy to spread decentralized apps among the people by hiding the complexity.
Ballerina is a JSON friendly language. It is easy to write programs for the JSON RPC API if we have a connector for Ethereum. Ballerina is also an integration tool and can be used to easily integrate the Ethereum JSON RPC API with other endpoints.
The Ethereum connector allows you to access the Ethereum JSON RPC API through Ballerina. The Ethereum connector actions are invoked using a Ballerina main function. The following diagram illustrates how Ballerina connects to the JSON RPC-enabled server, which in turn integrates with the Ethereum network.
The following sections provide you with information on how to use the Ballerina Ethereum connector.
- Download the Ballerina tool distribution by navigating to https://ballerinalang.org/downloads/.
- Extract
ballerina-ethereum-0.95.0.zipand copy theballerina-ethereum-0.95.0.jarfile into the<ballerina-tools>/bre/libfolder.
- Enable JSON RPC API in your Ethereum client node by visiting https://github.com/ethereum/wiki/wiki/JSON-RPC/.
- Identify the URI for the JSON RPC server. Default JSON-RPC endpoints:
| Client | URL |
|---|---|
| C++ | http://localhost:8545 |
| Go | http://localhost:8545 |
| Py | http://localhost:4000 |
| Parity | http://localhost:8545 |
-
Copy the
connector-ethereum/component/samples/ethereum/sampleDashBoard.balfile and paste it into the<ballerina-tools>/binfolder. -
Run the following command to execute the sample.
bin$ ballerina run sampleDashBoard.bal <URI> <JSONRPCVersion> <NetworkID>E.g.,
bin$ ballerina run sampleDashBoard.bal "http://localhost:8080" "2.0" 1999
You can easily test the following actions using the sample.bal file.
- Copy
connector-ethereum/component/samples/ethereum/sample.balfile and paste it into<ballerina-tools>/binfolder. - Run the following commands to execute the sample.
bin$ ballerina run sample.bal <URI> <JSONRPCVersion> <NetworkID> <MethodName> <Param1> .. <ParamN>
All the actions return a JSON payload and a http:HttpConnectorError. The JSON payload consists of either a result or an error. The following section provides details on the result of the JSON payload for each action under the Returns section.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.web3ClientVersion("2.0", 1999);
if (e == null) {
println(response);
println(response.result.toString());
} else {
println(e);
}//result
{"jsonrpc":"2.0","id":1999,"result":"Geth/hostname/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9"}
Geth/hostname/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9The Ethereum connector supports unimplemented RPC API functions via remoteProcedureCall().
response, e = ethereumConnector.remoteProcedureCall(JSONRPCVersion, networkId, "method_name", [params]);
if (e == null) {
println(response);
} else {
println(e);
}Returns the current client version.
string- JSON RPC versionint- network id
- The current client version
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.web3ClientVersion("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "Geth/hostname/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 web3_clientVersion
https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_clientversion
Returns Keccak-256 (not the standardized SHA3-256) of the given data.
string- JSON RPC versionint- network idstring- the data to convert into a SHA3 hash
- The SHA3 result of the given string.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.web3Sha3("2.0", 1999, "0x88656c6c6f20776f726c64");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0xdf52f504725deca82f038d245711867631f97c819931abe097301d9340c729ea"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 web3_sha3 "0x4521"
https://github.com/ethereum/wiki/wiki/JSON-RPC#web3_sha3
Returns the current network id.
string- JSON RPC versionint- network id
- The current network id.
"1": Ethereum Mainnet"2": Morden Testnet (deprecated)"3": Ropsten Testnet"4": Rinkeby Testnet"42": Kovan Testnet
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.netVersion("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "1999"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 net_version
https://github.com/ethereum/wiki/wiki/JSON-RPC#net_version
Returns true if client is actively listening for network connections.
string- JSON RPC versionint- network id
truewhen listening, otherwisefalse.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.netListening("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": true
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 net_listening
https://github.com/ethereum/wiki/wiki/JSON-RPC#net_listening
Returns number of peers currently connected to the client.
string- JSON RPC versionint- network id
- integer of the number of connected peers.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.netPeerCount("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x3"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 net_peerCount
https://github.com/ethereum/wiki/wiki/JSON-RPC#net_peercount
Returns the current ethereum protocol version.
string- JSON RPC versionint- network id
- The current ethereum protocol version
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethProtocolVersion("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x3f"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_protocolVersion
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_protocolversion
Returns an object with data about the sync status or false.
string- JSON RPC versionint- network id
- An object with sync status data or
FALSE, when not syncing:startingBlock: The block at which the import started (will only be reset, after the sync reached his head)currentBlock: The current block, same as ethBlockNumberhighestBlock: The estimated highest block
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethSyncing("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc": "2.0",
"result": {
"startingBlock": "0x384",
"currentBlock": "0x386",
"highestBlock": "0x454"
}
}{
"id":1999,
"jsonrpc": "2.0",
"result": false
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_syncing
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_syncing
Returns the client coinbase address.
string- JSON RPC versionint- network id
- 20 bytes - the current coinbase address.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethCoinbase("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_coinbase
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_coinbase
Returns true if client is actively mining new blocks.
string- JSON RPC versionint- network id
- returns
trueof the client is mining, otherwisefalse.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethMining("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": false
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_mining
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_mining
Returns the number of hashes per second that the node is mining with.
string- JSON RPC versionint- network id
- number of hashes per second.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethHashrate("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x5c84"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_hashrate
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_hashrate
Returns the current price per gas in wei.
string- JSON RPC versionint- network id
- integer of the current gas price in wei.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGasPrice("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x430e23400"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_gasPrice
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gasprice
Returns a list of addresses owned by client.
string- JSON RPC versionint- network id
- 20 Bytes - addresses owned by the client.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethAccounts("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": ["0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87","0xee76e1d9ad8859ac9340b07e6901a028a1101577"]
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_accounts
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_accounts
Returns the number of most recent block.
string- JSON RPC versionint- network id
- integer of the current block number the client is on.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethBlockNumber("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x58a"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_blockNumber
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_blocknumber
Returns the balance of the account of given address.
string- JSON RPC versionint- network idstring, 20 Bytes - address to check for balance.string- integer block number, or the string"latest","earliest"or"pending".
- integer of the current balance in wei.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetBalance("2.0", 1999, "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87", "latest");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x1085561b6057e826000"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getBalance 0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87 latest
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance
Returns the value from a storage position at a given address.
string- JSON RPC versionint- network idstring, 20 Bytes - address of the storage.string- integer of the position in the storage.string- integer block number, or the string"latest","earliest"or"pending".
- the value at this storage position.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetStorageAt("2.0", 1999, "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87", "0x0", "latest");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x00000000000000000000000000000000000000000000000000000000000005d3"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getStorageAt 0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87 0x0 latest
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getstorageat
Returns the number of transactions sent from an address.
string- JSON RPC versionint- network idstring, 20 Bytes - address.string- integer block number, or the string"latest","earliest"or"pending".
- integer of the number of transactions send from this address.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetTransactionCount("2.0", 1999, "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87", "latest");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x19"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getTransactionCount 0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87 0x0
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactioncount
Returns the number of transactions in a block from a block matching the given block hash.
string- JSON RPC versionint- network idstring, 32 Bytes - hash of a block
- integer of the number of transactions in this block.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetBlockTransactionCountByHash("2.0", 1999, "0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x1"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getBlockTransactionCountByHash 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbyhash
Returns the number of transactions in a block matching the given block number.
string- JSON RPC versionint- network idstring- integer of a block number, or the string"earliest","latest"or"pending".
- integer of the number of transactions in this block.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetBlockTransactionCountByNumber("2.0", 1999, "latest");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x0"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getBlockTransactionCountByNumber 0x0
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblocktransactioncountbynumber
Returns the number of uncles in a block from a block matching the given block hash.
string- JSON RPC versionint- network idstring, 32 Bytes - hash of a block
- integer of the number of uncles in this block.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetUncleCountByBlockHash("2.0", 1999, "0xe841dbd4630fde75a70dc221911aa289756827cd8dd909510215609adaf58655");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0xc3"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getUncleCountByBlockHash 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblockhash
Returns the number of uncles in a block from a block matching the given block number.
string- JSON RPC versionint- network idstring- integer of a block number, or the string "latest", "earliest" or "pending".
- integer of the number of uncles in this block.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetUncleCountByBlockNumber("2.0", 1999, "latest");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0xa2"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getUncleCountByBlockNumber 0x0
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclecountbyblocknumber
Returns code at a given address.
string- JSON RPC versionint- network idstring, 20 Bytes - addressstring- integer block number, or the string"latest","earliest"or"pending".
- the code from the given address.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetCode("2.0", 1999, "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x2");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getCode 0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87 latest
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode
The sign method calculates an Ethereum specific signature with.
string- JSON RPC versionint- network idstring, 20 Bytes - account addressstring, N Bytes - message to sign
string: Signature
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethSign("2.0", 1999, "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87", "0xdeadbeaf");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x725b107db88f11690dd6f2031f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_sign 0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87 0x170b651e078b2b0c073bffdb5dc53288ac0a62e1015f230e5ff5092c10eb56e4
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
Creates new message call transaction or a contract creation, if the data field contains code.
string- JSON RPC versionint- network idjson- The transaction object
from: 20 Bytes - The address the transaction is send from.to: 20 Bytes - (optional when creating new contract) The address the transaction is directed to.gas: - (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.gasPrice: (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gasvalue: (optional) Integer of the value send with this transactiondata: The compiled code of a contract OR the hash of the invoked method signature and encoded parameters.nonce: (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
- 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethSendTransaction("2.0", 1999,
{
from :"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
to: "0xee76e1d9ad8859ac9340b07e6901a028a1101577",
data: "0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c",
value: "0xa"
});
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x1c80b47e4a28c7c4892460c84a1f7b10aa2a33f0059f881abbcf77ef7ae2914a"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_sendTransaction '{"from" :"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87","to": "0xee76e1d9ad8859ac9340b07e6901a028a1101577","data": "0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c","value": "0xa"}'
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendtransaction
Creates new message call transaction or a contract creation for signed transactions.
string- JSON RPC versionint- network idstring, The signed transaction data.
- 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethSendRawTransaction("2.0", 1999, "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_sendRawTransaction 0x877399ae278d0a969bad46d3d2e4b2403d091b5c3fdab13c254c8ee09c6c591d17e058baaa8c5c4f2e3afc2fce30d1bce185e78307637d4cd67d0ad177b812e61c
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sendrawtransaction
Executes a new message call immediately without creating a transaction on the block chain.
string- JSON RPC versionint- network idjson- The transaction call object
from: 20 Bytes - (optional) The address the transaction is sent from.to: 20 Bytes - The address the transaction is directed to.gas: (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions.gasPrice: (optional) Integer of the gasPrice used for each paid gas.value: (optional) Integer of the value send with this transaction.data: (optional) Hash of the method signature and encoded parameters.
string- integer block number, or the string"latest","earliest"or"pending".
- the return value of executed contract.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethCall("2.0", 1999, {
from :"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
to: "0xee76e1d9ad8859ac9340b07e6901a028a1101577",
data: "0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c",
value: "0xa"
}, "latest");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_call '{"to":"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87"}' latest
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_call
Makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas.
In eth_call, all the optional parameters are expected.
- the amount of gas used.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethEstimateGas("2.0", 1999, {see above ethCall parameters});
if (e == null) {
println(response);
} else {
println(e);
}//result
{
"id":1999,
"jsonrpc":"2.0",
"result": "0x5208"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_estimateGas '{"from" :"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87","to": "0xee76e1d9ad8859ac9340b07e6901a028a1101577", "data": "0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c","value": "0xa"}'
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_estimategas
Returns information about a block by hash.
string- JSON RPC versionint- network idstring, 32 Bytes - Hash of a block.boolean- Iftrueit returns the full transaction objects, iffalseonly the hashes of the transactions.
json - A block object, or null when no block was found:
number: the block number.nullwhen its pending block.hash: 32 Bytes - hash of the block.nullwhen its pending block.parentHash: 32 Bytes - hash of the parent block.nonce: 8 Bytes - hash of the generated proof-of-work.nullwhen its pending block.sha3Uncles: 32 Bytes - SHA3 of the uncles data in the block.logsBloom: 256 Bytes - the bloom filter for the logs of the block.nullwhen its pending block.transactionsRoot: 32 Bytes - the root of the transaction trie of the block.stateRoot: 32 Bytes - the root of the final state trie of the block.receiptsRoot: 32 Bytes - the root of the receipts trie of the block.miner: 20 Bytes - the address of the beneficiary to whom the mining rewards were given.difficulty: integer of the difficulty for this block.totalDifficulty: integer of the total difficulty of the chain until this block.extraData: the "extra data" field of this block.size: integer the size of this block in bytes.gasLimit: the maximum gas allowed in this block.gasUsed: the total used gas by all transactions in this block.timestamp: the unix timestamp for when the block was collated.transactions: Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.uncles: Array of uncle hashes.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetBlockByHash("2.0", 1999, "0x8655b1b7949f45a95a77c8ff3942116db22ce268b5f63d2c25f09b5625b02607", true);
if (e == null) {
println(response);
} else {
println(e);
}//result
{
"id":1999,
"jsonrpc":"2.0",
"result": {
"difficulty":"0x20000",
"extraData":"0xd583010703846765746885676f312e39856c696e7578",
"gasLimit":"0x1ffffac",
"gasUsed":"0xc598",
"hash":"0x8655b1b7949f45a95a77c8ff3942116db22ce268b5f63d2c25f09b5625b02607",
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner":"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
"mixHash":"0x18ac3092c321f767a4274e242dc96fead605557323990e2550e72354caa26762",
"nonce":"0x2d2181ff742a9379",
"number":"0x58b",
"parentHash":"0xe841dbd4630fde75a70dc221911aa289756827cd8dd909510215609adaf58655",
"receiptsRoot":"0x67263eed0bbdb4aa419fa2f0673ce7c33f9b1c1dee3fa4618c25d7653d6341c1",
"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size":"0x36e",
"stateRoot":"0x79f41be89d58f5e8544e348442c3565222fa854c5c0b5cca7fdc62badd4dc3bf",
"timestamp":"0x5a684e62",
"totalDifficulty":"0xbeb62a4",
"transactions":[
{"blockHash":"0x8655b1b7949f45a95a77c8ff3942116db22ce268b5f63d2c25f09b5625b02607",
"blockNumber":"0x58b","from":"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
"gas":"0x15f90",
"gasPrice":"0x430e23400",
"hash":"0x1c80b47e4a28c7c4892460c84a1f7b10aa2a33f0059f881abbcf77ef7ae2914a",
"input":"0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c",
"nonce":"0x19","to":"0xee76e1d9ad8859ac9340b07e6901a028a1101577",
"transactionIndex":"0x0",
"value":"0xa",
"v":"0x42",
"r":"0x7439005bf1616c79a13ccb98b9020d791a801436e16b69ae3bdf04954760e1e3",
"s":"0x7b400bc21ca9649511f681bc46be18d7cd0ddc74d03b1095ef78bb4231fbcded"},
{"blockHash":"0x8655b1b7949f45a95a77c8ff3942116db22ce268b5f63d2c25f09b5625b02607",
"blockNumber":"0x58b","from":"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
"gas":"0x15f90",
"gasPrice":"0x430e23400",
"hash":"0x718a5076ef9f9937a2671e8767b37805692295533d2072b7c89f8d2f2999d844",
"input":"0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c",
"nonce":"0x1a",
"to":"0xee76e1d9ad8859ac9340b07e6901a028a1101577",
"transactionIndex":"0x1",
"value":"0xa",
"v":"0x42",
"r":"0xe60bea606b55ee3991c924fac76135a7acaeac5f0df5d0308c42679e003c952e",
"s":"0x71f1e1cefa266d0a8485a746ab05a257306d7d928523f10d617c698b3064b850"}],
"transactionsRoot":"0x6e7538c2e6c2747b9c6ff0932931bad93574cab5ea702a8d9064818eb17d278e",
"uncles":[]
}
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getBlockByHash 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef true
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbyhash
Returns information about a block by block number.
string- JSON RPC versionint- network idstring- integer of a block number, or the string"earliest","latest"or"pending".string- Iftrueit returns the full transaction objects, iffalseonly the hashes of the transactions.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getBlockByNumber 0xaf true
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber
Returns the information about a transaction requested by transaction hash.
string- JSON RPC versionint- network idstring, 32 Bytes - hash of a transaction
json - A transaction object, or null when no transaction was found:
hash: 32 Bytes - hash of the transaction.nonce: the number of transactions made by the sender prior to this one.blockHash: 32 Bytes - hash of the block where this transaction was in.nullwhen its pending.blockNumber: block number where this transaction was in.nullwhen its pending.transactionIndex: integer of the transactions index position in the block.nullwhen its pending.from: 20 Bytes - address of the sender.to: 20 Bytes - address of the receiver.nullwhen its a contract creation transaction.value: value transferred in Wei.gasPrice: gas price provided by the sender in Wei.gas: gas provided by the sender.input: the data send along with the transaction.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetTransactionByHash("2.0", 1999, "0x1c80b47e4a28c7c4892460c84a1f7b10aa2a33f0059f881abbcf77ef7ae2914a");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": {
"blockHash":"0x8655b1b7949f45a95a77c8ff3942116db22ce268b5f63d2c25f09b5625b02607",
"blockNumber":"0x58b",
"from":"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
"gas":"0x15f90",
"gasPrice":"0x430e23400",
"hash":"0x1c80b47e4a28c7c4892460c84a1f7b10aa2a33f0059f881abbcf77ef7ae2914a",
"input":"0x725b107db88f11690dd6f2032f260a0a93d735bd15e503d71bdbc1d7e73141a44bbeab080014866506b1e64281fc20690068a02f95298a09dd878e2272ca70b01c",
"nonce":"0x19",
"to":"0xee76e1d9ad8859ac9340b07e6901a028a1101577",
"transactionIndex":"0x0",
"value":"0xa",
"v":"0x42",
"r":"0x7439005bf1616c79a13ccb98b9020d791a801436e16b69ae3bdf04954760e1e3",
"s":"0x7b400bc21ca9649511f681bc46be18d7cd0ddc74d03b1095ef78bb4231fbcded"
}
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getTransactionByHash 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash
Returns information about a transaction by block hash and transaction index position.
string- JSON RPC versionint- network idstring, 32 Bytes - hash of a block.string- integer of the transaction index position.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getTransactionByBlockHashAndIndex 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef 0x0
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblockhashandindex
Returns information about a transaction by block number and transaction index position.
string- JSON RPC versionint- network idstring- a block number, or the string"earliest","latest"or"pending".string- the transaction index position.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getTransactionByBlockNumberAndIndex 0xaf 0x0
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyblocknumberandindex
Returns the receipt of a transaction by transaction hash.
Note That the receipt is not available for pending transactions.
string- JSON RPC versionint- network idstring, 32 Bytes - hash of a transaction
json - A transaction receipt object, or null when no receipt was found:
transactionHash: 32 Bytes - hash of the transaction.transactionIndex: integer of the transactions index position in the block.blockHash: 32 Bytes - hash of the block where this transaction was in.blockNumber: block number where this transaction was in.cumulativeGasUsed: The total amount of gas used when this transaction was executed in the block.gasUsed: The amount of gas used by this specific transaction alone.contractAddress: 20 Bytes - The contract address created, if the transaction was a contract creation, otherwisenull.logs: Array of log objects, which this transaction generated.logsBloom: 256 Bytes - Bloom filter for light clients to quickly retrieve related logs.
It also returns either :
root: 32 bytes of post-transaction stateroot (pre Byzantium)status: either1(success) or0(failure)
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetTransactionReceipt("2.0", 1999, "0x1c80b47e4a28c7c4892460c84a1f7b10aa2a33f0059f881abbcf77ef7ae2914a");
if (e == null) {
println(response);
} else {
println(e);
}//result
{
"id":1999,
"jsonrpc":"2.0",
"result": {
"blockHash":"0x8655b1b7949f45a95a77c8ff3942116db22ce268b5f63d2c25f09b5625b02607",
"blockNumber":"0x58b",
"contractAddress":null,
"cumulativeGasUsed":"0x62cc",
"from":"0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
"gasUsed":"0x62cc",
"logs":[],
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root":"0x53a4e4f95ec028e158f8ac7d9f57993e0e13e4582cce0e0f072f58d41e6f9e22",
"to":"0xee76e1d9ad8859ac9340b07e6901a028a1101577",
"transactionHash":"0x1c80b47e4a28c7c4892460c84a1f7b10aa2a33f0059f881abbcf77ef7ae2914a",
"transactionIndex":"0x0"
}
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getTransactionReceipt 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionreceipt
Returns information about a uncle of a block by hash and uncle index position.
string- JSON RPC versionint- network idstring, 32 Bytes - hash a block.string- the uncle's index position.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getUncleByBlockHashAndIndex 0xf6c17bf68c909565f2f1766da00a0f44e52ecb381ac6c8e088d28273d92e79ef 0x0'
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblockhashandindex
Returns information about a uncle of a block by number and uncle index position.
string- JSON RPC versionint- network idstring- a block number, or the string"earliest","latest"or"pending".string- the uncle's index position.
Note: An uncle doesn't contain individual transactions.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getUncleByBlockNumberAndIndex 0xf6 0x0
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getunclebyblocknumberandindex
Returns a list of available compilers in the client.
string- JSON RPC versionint- network id
- Array of available compilers.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetCompilers("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": ["solidity", "lll", "serpent"]
}https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcompilers
Returns compiled solidity code.
string- JSON RPC versionint- network idstring- The source code.
- The compiled source code.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethCompileSolidity("2.0", 1999,
"contract test { function multiply(uint a) returns(uint d) { return a * 7; } }");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc": "2.0",
"result": {
"code": "0x605880600c6000396000f3006000357c010000000000000000000000000000000000000000000000000000000090048063c6888fa114602e57005b603d6004803590602001506047565b8060005260206000f35b60006007820290506053565b91905056",
"info": {
"source": "contract test {\n function multiply(uint a) constant returns(uint d) {\n return a * 7;\n }\n}\n",
"language": "Solidity",
"languageVersion": "0",
"compilerVersion": "0.9.19",
"abiDefinition": [
{
"constant": true,
"inputs": [
{
"name": "a",
"type": "uint256"
}
],
"name": "multiply",
"outputs": [
{
"name": "d",
"type": "uint256"
}
],
"type": "function"
}
],
"userDoc": {
"methods": {}
},
"developerDoc": {
"methods": {}
}
}
}https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilesolidity
Returns compiled LLL code.
string- JSON RPC versionint- network idstring- The source code.
- The compiled source code.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethCompileLLL("2.0", 1999, "(returnlll (suicide (caller)))");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056"
}https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compilelll
Returns compiled serpent code.
string- JSON RPC versionint- network idstring- The source code.
- The compiled source code.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethCompileSerpent("2.0", 1999, "Some code");
if (e == null) {
println(response);
} else {
println(e);
}//result
{
"id":1999,
"jsonrpc":"2.0",
"result": "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056"
}https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_compileserpent
Creates a filter object, based on filter options, to notify when the state changes (logs).
string- JSON RPC versionint- network idjson- The filter options:
fromBlock: (optional, default:"latest") Integer block number, or"latest"for the last mined block or"pending","earliest"for not yet mined transactions.toBlock: (optional, default:"latest") Integer block number, or"latest"for the last mined block or"pending","earliest"for not yet mined transactions.address: 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate.topics: (optional) Array of 32 BytesDATAtopics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.
- A filter id.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethNewFilter("2.0", 1999, {
"fromBlock": "0x1",
"toBlock": "0x2",
"address": "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87",
"topics": ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null, ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]
});
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0xcce8842bc862eec936b6ca0c392c8633"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_newFilter '{"fromBlock": "0x1","toBlock": "0x2","address": "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87","topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null,["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]}'
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter
Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call ethGetFilterChanges.
string- JSON RPC versionint- network id
- A filter id.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethNewBlockFilter("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0xd1e74a0ecefd34817099171b8b9e8a82"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_newBlockFilter
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newblockfilter
Creates a filter in the node, to notify when new pending transactions arrive.
string- JSON RPC versionint- network id
- A filter id.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethNewPendingTransactionFilter("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": "0x1bad3335bdd994b7a4690f0a134fb340"
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_newPendingTransactionFilter
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newpendingtransactionfilter
Uninstalls a filter with given id.
string- JSON RPC versionint- network idstring- The filter id.
trueif the filter was successfully uninstalled, otherwisefalse.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethUninstallFilter("2.0", 1999, "0xd1e74a0ecefd34817099171b8b9e8a82");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": true
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_uninstallFilter 0x15842a94627e19e5571559236b5b1700
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_uninstallfilter
Polling method for a filter, which returns an array of logs which occurred since last poll.
string- JSON RPC versionint- network idstring- the filter id.
json - Array of log objects, or an empty array if nothing has changed since last poll.
-
For filters created with
ethNewBlockFilterthe return are block hashes (string, 32 Bytes), e.g.["0x3454645634534..."]. -
For filters created with
ethNewPendingTransactionFilterthe return are transaction hashes (string, 32 Bytes), e.g.["0x6345343454645..."]. -
For filters created with
ethNewFilterlogs are objects with following params:removed:truewhen the log was removed, due to a chain reorganization.falseif its a valid log.logIndex: integer of the log index position in the block.nullwhen its pending log.transactionIndex: integer of the transactions index position log was created from.nullwhen its pending log.transactionHash: 32 Bytes - hash of the transactions this log was created from.nullwhen its pending log.blockHash: 32 Bytes - hash of the block where this log was in.nullwhen its pending.nullwhen its pending log.blockNumber: the block number where this log was in.nullwhen its pending.nullwhen its pending log.address: 20 Bytes - address from which this log originated.data: contains one or more 32 Bytes non-indexed arguments of the log.topics:Array of string- Array of 0 to 4, 32 Bytesstringof indexed log arguments.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetFilterChanges("2.0", 1999, "0x1bad3335bdd994b7a4690f0a134fb340");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": [{
"logIndex": "0x1",
"blockNumber":"0x5f9",
"blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d",
"transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf",
"transactionIndex": "0x0",
"address": "0x1bad3335bdd994b7a4690f0a134fb340f1fccd7d",
"data":"0x0000000000000000000000000000000000000000000000000000000000000000",
"topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"]
},{
}]
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getFilterChanges 0x15842a94627e19e5571559236b5b1700
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterchanges
Returns an array of all logs matching filter with given id.
string- JSON RPC versionint- network idstring- The filter id.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getFilterLogs 0x15842a94627e19e5571559236b5b1700
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs
Returns an array of all logs matching a given filter object.
string- JSON RPC versionint- network idjson- the filter object, see eth_newFilter parameters.
bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getLogs '{"fromBlock": "0x1","toBlock": "0x2","address": "0x0eb8a07d29f5afdcbec1a9d087ece456139bfb87","topics":["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null,["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]}'
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getLogs
Returns the hash of the current block, the seedHash, and the boundary condition to be met ("target").
none
json - Array with the following properties:
string, 32 Bytes - current block header pow-hashstring, 32 Bytes - the seed hash used for the DAG.string, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethGetWork("2.0", 1999);
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": ["0xe77859f2a6cce904a1d7a2f84d4e18ba8ad877bc816c4544975be03be1fef938","0x0000000000000000000000000000000000000000000000000000000000000000","0x00007fb031e0d37bd29c5e4514d2fc226a7d7199005fc425689e9cddf546b3ce"]
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_getWork
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getwork
Used for submitting a proof-of-work solution.
string- JSON RPC versionint- network idstring, 8 Bytes - The nonce found (64 bits)string, 32 Bytes - The header's pow-hash (256 bits)string, 32 Bytes - The mix digest (256 bits)
- returns
trueif the provided solution is valid, otherwisefalse.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethSubmitWork("2.0", 1999, "0x0000000000000001", "0xa234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000D1GE5700000000000000000000000000");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": true
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_submitWork "0x0000000000000001" "0xa234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submitwork
Used for submitting mining hashrate.
string- JSON RPC versionint- network idstring- a hexadecimal string representation (32 bytes) of the hash ratestring- A random hexadecimal(32 bytes) ID identifying the client
- returns
trueif submitting went through succesfully andfalseotherwise.
//code
json response = {};
http:HttpConnectorError e;
response, e = ethereumConnector.ethSubmitHashrate("2.0", 1999, "0x0000000000000000000000000000000000000000000000000000000000500000", "0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c");
if (e == null) {
println(response);
} else {
println(e);
}{
"id":1999,
"jsonrpc":"2.0",
"result": true
}bin$ ballerina run sample.bal "http://localhost:8080" "2.0" 1999 eth_submitHashrate "0x500000" "0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c"
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_submithashrate
