JSON-RPC
Last updated
Was this helpful?
Last updated
Was this helpful?
In order for a software application to interact with the Electroneum Smart Chain - either by reading blockchain data or sending transactions to the network - it must connect to an Electroneum Smart Chain node.
For this purpose, every implements a , so there is a uniform set of methods that applications can rely on regardless of the specific node or client implementation.
is a stateless, light-weight remote procedure call (RPC) protocol. It defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments. It uses JSON (RFC 4627) as data format.
While you may choose to interact directly with Electroneum Smart Chain clients via the JSON-RPC API, there are often easier options for dapp developers. Many libraries exist to provide wrappers on top of the JSON-RPC API. With these libraries, developers can write intuitive, one-line methods in the programming language of their choice to initialize JSON-RPC requests (under the hood) that interact with the Electroneum Smart Chain.
Two key data types get passed over JSON: unformatted byte arrays and quantities. Both are passed with a hex encoding but with different requirements for formatting.
When encoding quantities (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0").
Here are some examples:
0x41 (65 in decimal)
0x400 (1024 in decimal)
WRONG: 0x (should always have at least one digit - zero is "0x0")
WRONG: 0x0400 (no leading zeroes allowed)
WRONG: ff (must be prefixed 0x)
When encoding unformatted data (byte arrays, account addresses, hashes, bytecode arrays): encode as hex, prefix with "0x", two hex digits per byte.
Here are some examples:
0x41 (size 1, "A")
0x004200 (size 3, "\0B\0")
0x (size 0, "")
WRONG: 0xf0f0f (must be even number of digits)
WRONG: 004200 (must be prefixed 0x)
The following methods have an extra default block parameter:
When requests are made that act on the state of Electroneum Smart Chain, the last default block parameter determines the height of the block.
The following options are possible for the defaultBlock
parameter:
HEX String
- an integer block number
String "earliest"
for the earliest/genesis block
String "latest"
- for the latest mined block
String "safe"
- for the latest safe head block
String "finalized"
- for the latest finalized block
String "pending"
- for the pending state/transactions
The curl requests might return an error message relating to the content type. This is because the --data
option sets the content type to application/x-www-form-urlencoded
. If your node does complain about this, manually set the header by placing -H "Content-Type: application/json"
at the start of the call. The examples also do not include the URL/IP & port combination which must be the last argument given to curl (e.g. 127.0.0.1:8545
). A complete curl request including these additional data takes the following form:
A handful of core JSON-RPC methods require data from the Electroneum Smart Chain network, and fall neatly into three main categories: Gossip, State, and History. Use the links in these sections to jump to each method, or use the table of contents to explore the whole list of methods.
These methods track the head of the chain. This is how transactions make their way around the network, find their way into blocks, and how clients find out about new blocks.
Methods that report the current state of all the data stored. The "state" is like one big shared piece of RAM, and includes account balances, contract data, and gas estimations.
Fetches historical records of every block back to genesis. This is like one large append-only file, and includes all block headers, block bodies, uncle blocks, and transaction receipts.
Returns the current client version.
Parameters
None
Returns
String
- The current client version
Example
Returns Keccak-256 (not the standardized SHA3-256) of the given data.
Parameters
DATA
- the data to convert into a SHA3 hash
Returns
DATA
- The SHA3 result of the given string.
Example
Returns the current network id.
Parameters
None
Returns
String
- The current network id.
52014
: Electroneum Smart Chain Mainnet
5201420
: Electroneum Smart Chain Testnet
5201419
: Electroneum Smart Chain Stagenet
Example
Returns true
if client is actively listening for network connections.
Parameters
None
Returns
Boolean
- true
when listening, otherwise false
.
Example
Returns number of peers currently connected to the client.
Parameters
None
Returns
QUANTITY
- integer of the number of connected peers.
Example
Returns an object with data about the sync status or false
.
Parameters
None
Returns
Object|Boolean
, An object with sync status data or FALSE
, when not syncing:
startingBlock
: QUANTITY
- The block at which the import started (will only be reset, after the sync reached his head)
currentBlock
: QUANTITY
- The current block, same as eth_blockNumber
highestBlock
: QUANTITY
- The estimated highest block
Example
Returns the client coinbase address.
Parameters
None
Returns
DATA
, 20 bytes - the current coinbase address.
Example
Returns the chain ID used for signing replay-protected transactions.
Parameters
None
Returns
chainId
, hexadecimal value as a string representing the integer of the current chain id.
Example
Returns true
if client is actively mining new blocks.
Parameters
None
Returns
Boolean
- returns true
of the client is mining, otherwise false
.
Example
Returns the number of hashes per second that the node is mining with. Not applicable to IBFT.
Parameters
None
Returns
QUANTITY
- number of hashes per second.
Example
Returns the current price per gas in wei.
Parameters
None
Returns
QUANTITY
- integer of the current gas price in wei.
Example
Returns a list of addresses owned by client.
Parameters
None
Returns
Array of DATA
, 20 Bytes - addresses owned by the client.
Example
Returns the number of most recent block.
Parameters
None
Returns
QUANTITY
- integer of the current block number the client is on.
Example
Returns the balance of the account of given address.
Parameters
DATA
, 20 Bytes - address to check for balance.
Returns
QUANTITY
- integer of the current balance in wei.
Example
Returns the value from a storage position at a given address.
Parameters
DATA
, 20 Bytes - address of the storage.
QUANTITY
- integer of the position in the storage.
Returns
DATA
- the value at this storage position.
Example Calculating the correct position depends on the storage to retrieve. Consider the following contract deployed at 0x295a70b2de5e3953354a6a8344e616ed314d7251
by address 0x391694e7e0b0cce554cb130d723a9d27458f9298
.
Retrieving the value of pos0 is straight forward:
Retrieving an element of the map is harder. The position of an element in the map is calculated with:
This means to retrieve the storage on pos1["0x391694e7e0b0cce554cb130d723a9d27458f9298"] we need to calculate the position with:
The etn-sc console which comes with the web3 library can be used to make the calculation:
Now to fetch the storage:
Returns the number of transactions sent from an address.
Parameters
DATA
, 20 Bytes - address.
Returns
QUANTITY
- integer of the number of transactions send from this address.
Example
Returns the number of transactions in a block from a block matching the given block hash.
Parameters
DATA
, 32 Bytes - hash of a block
Returns
QUANTITY
- integer of the number of transactions in this block.
Example
Returns the number of transactions in a block matching the given block number.
Parameters
Returns
QUANTITY
- integer of the number of transactions in this block.
Example
Returns the number of uncles in a block from a block matching the given block hash.
Parameters
DATA
, 32 Bytes - hash of a block
Returns
QUANTITY
- integer of the number of uncles in this block.
Example
Returns the number of uncles in a block from a block matching the given block number.
Parameters
Returns
QUANTITY
- integer of the number of uncles in this block.
Example
Returns code at a given address.
Parameters
DATA
, 20 Bytes - address
Returns
DATA
- the code from the given address.
Example
The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Electroneum Signed Message:\n" + len(message) + message)))
.
By adding a prefix to the message makes the calculated signature recognizable as an Electroneum specific signature. This prevents misuse where a malicious dapp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.
Note: the address to sign with must be unlocked.
Parameters
DATA
, 20 Bytes - address
DATA
, N Bytes - message to sign
Returns
DATA
: Signature
Example
Parameters
Object
- The transaction object
from
: DATA
, 20 Bytes - The address the transaction is sent from.
to
: DATA
, 20 Bytes - (optional when creating new contract) The address the transaction is directed to.
gas
: QUANTITY
- (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.
gasPrice
: QUANTITY
- (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas, in Wei.
value
: QUANTITY
- (optional) Integer of the value sent with this transaction, in Wei.
data
: DATA
- The compiled code of a contract OR the hash of the invoked method signature and encoded parameters.
nonce
: QUANTITY
- (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
Returns
DATA
, The signed transaction object.
Example
Creates new message call transaction or a contract creation, if the data field contains code.
Parameters
Object
- The transaction object
from
: DATA
, 20 Bytes - The address the transaction is sent from.
to
: DATA
, 20 Bytes - (optional when creating new contract) The address the transaction is directed to.
gas
: QUANTITY
- (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.
gasPrice
: QUANTITY
- (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas.
value
: QUANTITY
- (optional) Integer of the value sent with this transaction.
data
: DATA
- The compiled code of a contract OR the hash of the invoked method signature and encoded parameters.
nonce
: QUANTITY
- (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
Returns
DATA
, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Example
Creates new message call transaction or a contract creation for signed transactions.
Parameters
DATA
, The signed transaction data.
Returns
DATA
, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Example
Executes a new message call immediately without creating a transaction on the block chain.
Parameters
Object
- The transaction call object
from
: DATA
, 20 Bytes - (optional) The address the transaction is sent from.
to
: DATA
, 20 Bytes - The address the transaction is directed to.
gas
: QUANTITY
- (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
: QUANTITY
- (optional) Integer of the gasPrice used for each paid gas
value
: QUANTITY
- (optional) Integer of the value sent with this transaction
Returns
DATA
- the return value of executed contract.
Example
Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain. Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.
Parameters
Returns
QUANTITY
- the amount of gas used.
Example
Returns information about a block by hash.
Parameters
DATA
, 32 Bytes - Hash of a block.
Boolean
- If true
it returns the full transaction objects, if false
only the hashes of the transactions.
Returns
Object
- A block object, or null
when no block was found:
number
: QUANTITY
- the block number. null
when its pending block.
hash
: DATA
, 32 Bytes - hash of the block. null
when its pending block.
parentHash
: DATA
, 32 Bytes - hash of the parent block.
nonce
: DATA
, 8 Bytes - hash of the generated proof-of-work. null
when its pending block.
sha3Uncles
: DATA
, 32 Bytes - SHA3 of the uncles data in the block.
logsBloom
: DATA
, 256 Bytes - the bloom filter for the logs of the block. null
when its pending block.
transactionsRoot
: DATA
, 32 Bytes - the root of the transaction trie of the block.
stateRoot
: DATA
, 32 Bytes - the root of the final state trie of the block.
receiptsRoot
: DATA
, 32 Bytes - the root of the receipts trie of the block.
miner
: DATA
, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.
difficulty
: QUANTITY
- integer of the difficulty for this block.
totalDifficulty
: QUANTITY
- integer of the total difficulty of the chain until this block.
extraData
: DATA
- the "extra data" field of this block.
size
: QUANTITY
- integer the size of this block in bytes.
gasLimit
: QUANTITY
- the maximum gas allowed in this block.
gasUsed
: QUANTITY
- the total used gas by all transactions in this block.
timestamp
: QUANTITY
- the unix timestamp for when the block was collated.
transactions
: Array
- Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
uncles
: Array
- Array of uncle hashes.
Example
Returns information about a block by block number.
Parameters
Boolean
- If true
it returns the full transaction objects, if false
only the hashes of the transactions.
Example
Returns the information about a transaction requested by transaction hash.
Parameters
DATA
, 32 Bytes - hash of a transaction
Returns
Object
- A transaction object, or null
when no transaction was found:
blockHash
: DATA
, 32 Bytes - hash of the block where this transaction was in. null
when its pending.
blockNumber
: QUANTITY
- block number where this transaction was in. null
when its pending.
from
: DATA
, 20 Bytes - address of the sender.
gas
: QUANTITY
- gas provided by the sender.
gasPrice
: QUANTITY
- gas price provided by the sender in Wei.
hash
: DATA
, 32 Bytes - hash of the transaction.
input
: DATA
- the data send along with the transaction.
nonce
: QUANTITY
- the number of transactions made by the sender prior to this one.
to
: DATA
, 20 Bytes - address of the receiver. null
when its a contract creation transaction.
transactionIndex
: QUANTITY
- integer of the transactions index position in the block. null
when its pending.
value
: QUANTITY
- value transferred in Wei.
v
: QUANTITY
- ECDSA recovery id
r
: QUANTITY
- ECDSA signature r
s
: QUANTITY
- ECDSA signature s
Example
Returns information about a transaction by block hash and transaction index position.
Parameters
DATA
, 32 Bytes - hash of a block.
QUANTITY
- integer of the transaction index position.
Example
Returns information about a transaction by block number and transaction index position.
Parameters
QUANTITY
- the transaction index position.
Example
Returns the receipt of a transaction by transaction hash.
Note That the receipt is not available for pending transactions.
Parameters
DATA
, 32 Bytes - hash of a transaction
Returns Object
- A transaction receipt object, or null
when no receipt was found:
transactionHash
: DATA
, 32 Bytes - hash of the transaction.
transactionIndex
: QUANTITY
- integer of the transactions index position in the block.
blockHash
: DATA
, 32 Bytes - hash of the block where this transaction was in.
blockNumber
: QUANTITY
- block number where this transaction was in.
from
: DATA
, 20 Bytes - address of the sender.
to
: DATA
, 20 Bytes - address of the receiver. null when its a contract creation transaction.
cumulativeGasUsed
: QUANTITY
- The total amount of gas used when this transaction was executed in the block.
effectiveGasPrice
: QUANTITY
- The sum of the base fee and tip paid per unit of gas.
gasUsed
: QUANTITY
- The amount of gas used by this specific transaction alone.
contractAddress
: DATA
, 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null
.
logs
: Array
- Array of log objects, which this transaction generated.
logsBloom
: DATA
, 256 Bytes - Bloom filter for light clients to quickly retrieve related logs.
type
: QUANTITY
- integer of the transaction type, 0x0
for legacy transactions, 0x1
for access list types, 0x2
for dynamic fees.
It also returns either :
root
: DATA
32 bytes of post-transaction stateroot (pre Byzantium)
status
: QUANTITY
either 1
(success) or 0
(failure)
Example
Returns information about a uncle of a block by hash and uncle index position.
Parameters
DATA
, 32 Bytes - The hash of a block.
QUANTITY
- The uncle's index position.
Example
Note: An uncle doesn't contain individual transactions.
Returns information about a uncle of a block by number and uncle index position.
Parameters
QUANTITY
- the uncle's index position.
Note: An uncle doesn't contain individual transactions.
Example
Returns a list of available compilers in the client.
Parameters None
Returns Array
- Array of available compilers.
Example
Returns compiled solidity code.
Parameters
String
- The source code.
Returns DATA
- The compiled source code.
Example
Returns compiled LLL code.
Parameters
String
- The source code.
Returns DATA
- The compiled source code.
Example
Returns compiled serpent code.
Parameters
String
- The source code.
Returns DATA
- The compiled source code.
Example
A note on specifying topic filters: Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters:
[]
"anything"
[A]
"A in first position (and anything after)"
[null, B]
"anything in first position AND B in second position (and anything after)"
[A, B]
"A in first position AND B in second position (and anything after)"
[[A, B], [A, B]]
"(A OR B) in first position AND (A OR B) in second position (and anything after)"
Parameters
Object
- The filter options:
fromBlock
: QUANTITY|TAG
- (optional, default: "latest"
) Integer block number, or "latest"
for the last mined block or "pending"
, "earliest"
for not yet mined transactions.
toBlock
: QUANTITY|TAG
- (optional, default: "latest"
) Integer block number, or "latest"
for the last mined block or "pending"
, "earliest"
for not yet mined transactions.
address
: DATA|Array
, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate.
topics
: Array of DATA
, - (optional) Array of 32 Bytes DATA
topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.
Returns QUANTITY
- A filter id.
Example
Parameters None
Returns QUANTITY
- A filter id.
Example
Parameters None
Returns QUANTITY
- A filter id.
Example
Parameters
QUANTITY
- The filter id.
Returns Boolean
- true
if the filter was successfully uninstalled, otherwise false
.
Example
Polling method for a filter, which returns an array of logs which occurred since last poll.
Parameters
QUANTITY
- the filter id.
Returns Array
- Array of log objects, or an empty array if nothing has changed since last poll.
For filters created with eth_newBlockFilter
the return are block hashes (DATA
, 32 Bytes), e.g. ["0x3454645634534..."]
.
For filters created with eth_newPendingTransactionFilter
the return are transaction hashes (DATA
, 32 Bytes), e.g. ["0x6345343454645..."]
.
For filters created with eth_newFilter
logs are objects with following params:
removed
: TAG
- true
when the log was removed, due to a chain reorganization. false
if its a valid log.
logIndex
: QUANTITY
- integer of the log index position in the block. null
when its pending log.
transactionIndex
: QUANTITY
- integer of the transactions index position log was created from. null
when its pending log.
transactionHash
: DATA
, 32 Bytes - hash of the transactions this log was created from. null
when its pending log.
blockHash
: DATA
, 32 Bytes - hash of the block where this log was in. null
when its pending. null
when its pending log.
blockNumber
: QUANTITY
- the block number where this log was in. null
when its pending. null
when its pending log.
address
: DATA
, 20 Bytes - address from which this log originated.
data
: DATA
- contains one or more 32 Bytes non-indexed arguments of the log.
topics
: Array of DATA
- Array of 0 to 4 32 Bytes DATA
of indexed log arguments. (In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)
), except you declared the event with the anonymous
specifier.)
Example
Returns an array of all logs matching filter with given id.
Parameters
QUANTITY
- The filter id.
Example
Returns an array of all logs matching a given filter object.
Parameters
Object
- The filter options:
fromBlock
: QUANTITY|TAG
- (optional, default: "latest"
) Integer block number, or "latest"
for the last mined block or "pending"
, "earliest"
for not yet mined transactions.
toBlock
: QUANTITY|TAG
- (optional, default: "latest"
) Integer block number, or "latest"
for the last mined block or "pending"
, "earliest"
for not yet mined transactions.
address
: DATA|Array
, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate.
topics
: Array of DATA
, - (optional) Array of 32 Bytes DATA
topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.
blockhash
: DATA
, 32 Bytes - (optional, future) With the addition of EIP-234, blockHash
will be a new filter option which restricts the logs returned to the single block with the 32-byte hash blockHash
. Using blockHash
is equivalent to fromBlock
= toBlock
= the block number with hash blockHash
. If blockHash
is present in the filter criteria, then neither fromBlock
nor toBlock
are allowed.
Example
Returns the hash of the current block, the seedHash, and the boundary condition to be met ("target").
Parameters None
Returns Array
- Array with the following properties:
DATA
, 32 Bytes - current block header pow-hash
DATA
, 32 Bytes - the seed hash used for the DAG.
DATA
, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.
Example
Used for submitting a proof-of-work solution.
Parameters
DATA
, 8 Bytes - The nonce found (64 bits)
DATA
, 32 Bytes - The header's pow-hash (256 bits)
DATA
, 32 Bytes - The mix digest (256 bits)
Returns Boolean
- returns true
if the provided solution is valid, otherwise false
.
Example
Used for submitting mining hashrate.
Parameters
Hashrate
, a hexadecimal string representation (32 bytes) of the hashrate
ID
, String - A random hexadecimal(32 bytes) ID identifying the client
Returns Boolean
- returns true
if submitting went through successfully and false
otherwise.
Example
The first thing to do is make sure the HTTP RPC interface is enabled. This means we supply Etn-sc with the --http
flag on startup. In this example we use the Etn-sc node on a private development chain. Using this approach we don't need ether on the real network.
This will start the HTTP RPC interface on http://localhost:8545
.
Because numbers are hex encoded, the balance is returned in wei as a hex string. If we want to have the balance in ETN as a number we can use web3 from the Etn-sc console.
The next step is to compile the Multiply7 contract to byte code that can be send to the EVM.
Now that we have the compiled code we need to determine how much gas it costs to deploy it. The RPC interface has an eth_estimateGas
method that will give us an estimate.
And finally deploy the contract.
The transaction is accepted by the node and a transaction hash is returned. This hash can be used to track the transaction. The next step is to determine the address where our contract is deployed. Each executed transaction will create a receipt. This receipt contains various information about the transaction such as in which block the transaction was included and how much gas was used by the EVM. If a transaction creates a contract it will also contain the contract address. We can retrieve the receipt with the eth_getTransactionReceipt
RPC method.
Our contract was created on 0x4d03d617d700cf81935d7f797f4e2ae719648262
. A null result instead of a receipt means the transaction has not been included in a block yet. Wait for a moment and check if your miner is running and retry it.
In this example we will be sending a transaction using eth_sendTransaction
to the multiply
method of the contract.
The bytes of the payload defines which method in the contract is called. This is the first 4 bytes from the Keccak hash over the function name and its argument types, hex encoded. The multiply function accepts an uint which is an alias for uint256. This leaves us with:
The next step is to encode the arguments. There is only one uint256, say, the value 6. The ABI has a section which specifies how to encode uint256 types.
int<M>: enc(X)
is the big-endian two’s complement encoding of X, padded on the higher-order (left) side with 0xff for negative X and with zero > bytes for positive X such that the length is a multiple of 32 bytes.
This encodes to 0000000000000000000000000000000000000000000000000000000000000006
.
Combining the function selector and the encoded argument our data will be 0xc6888fa10000000000000000000000000000000000000000000000000000000000000006
.
This can now be sent to the node:
Since a transaction was sent, a transaction hash was returned. Retrieving the receipt gives:
The receipt contains a log. This log was generated by the EVM on transaction execution and included in the receipt. The multiply
function shows that the Print
event was raised with the input times 7. Since the argument for the Print
event was a uint256 we can decode it according to the ABI rules which will leave us with the expected decimal 42. Apart from the data it is worth noting that topics can be used to determine which event created the log:
This was just a brief introduction into some of the most common tasks, demonstrating direct usage of the JSON-RPC.
On this page we provide examples of how to use individual JSON_RPC API endpoints using the command line tool, . These individual endpoint examples are found below in the section. Further down the page, we also provide an for compiling and deploying a smart contract using a ETN-SC node, the JSON_RPC API and curl.
Examples of using the JSON_RPC API by making requests to an Electroneum Smart Chain node are provided below. Each example includes a description of the specific endpoint, its parameters, return type, and a worked example of how it should be used.
The full list of current network IDs is available at . Some common ones are:
QUANTITY|TAG
- integer block number, or the string "latest"
, "earliest"
or "pending"
, see the
QUANTITY|TAG
- integer block number, or the string "latest"
, "earliest"
or "pending"
, see the
QUANTITY|TAG
- integer block number, or the string "latest"
, "earliest"
or "pending"
, see the
QUANTITY|TAG
- integer of a block number, or the string "earliest"
, "latest"
or "pending"
, as in the .
QUANTITY|TAG
- integer of a block number, or the string "latest", "earliest" or "pending", see the
QUANTITY|TAG
- integer block number, or the string "latest"
, "earliest"
or "pending"
, see the
Signs a transaction that can be submitted to the network at a later time using with .
Use to get the contract address, after the transaction was mined, when you created a contract.
Use to get the contract address, after the transaction was mined, when you created a contract.
data
: DATA
- (optional) Hash of the method signature and encoded parameters. For details see
QUANTITY|TAG
- integer block number, or the string "latest"
, "earliest"
or "pending"
, see the
See parameters, except that all properties are optional. If no gas limit is specified etn-sc uses the block gas limit from the pending block as an upper bound. As a result the returned estimate might not be enough to executed the call/transaction when the amount of gas is higher than the pending block gas limit.
QUANTITY|TAG
- integer of a block number, or the string "earliest"
, "latest"
or "pending"
, as in the .
Returns See
Result see
Returns See
Result see
QUANTITY|TAG
- a block number, or the string "earliest"
, "latest"
or "pending"
, as in the .
Returns See
Result see
Returns See
Result see
QUANTITY|TAG
- a block number, or the string "earliest"
, "latest"
or "pending"
, as in the .
Returns See
Result see
Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call .
Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call .
Creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call .
Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additionally Filters timeout when they aren't requested with for a period of time.
Returns See
Result see
Returns See
Result see
This section includes a demonstration of how to deploy a contract using only the RPC interface. There are alternative routes to deploying contracts where this complexity is abstracted away—for example, using libraries built on top of the RPC interface such as and . These abstractions are generally easier to understand and less error-prone, but it is still helpful to understand what is happening under the hood.
The following is a straightforward smart contract called Multiply7
that will be deployed using the JSON-RPC interface to an Electroneum Smart Chain node. This tutorial assumes the reader is already running a ETN-SC node. More information on nodes and clients is available . Please refer to individual documentation to see how to start the HTTP JSON-RPC. Most clients default to serving on localhost:8545
.
We can verify that the interface is running by retrieving the Coinbase address and balance using . Please note that data in these examples will differ on your local node. If you want to try these commands, replace the request params in the second curl request with the result returned from the first.
Now that there is some ETN on our private development chain, we can deploy the contract. The first step is to compile the Multiply7 contract to byte code that can be sent to the EVM. To install solc, the Solidity compiler, follow the . (You might want to use an older solc
release to match .)
eth_sendTransaction
requires several arguments, specifically from
, to
and data
. From
is the public address of our account, and to
is the contract address. The data
argument contains a payload that defines which method must be called and with which arguments. This is where the comes into play. The ABI is a JSON file that defines how to define and encode data for the EVM.