⏲️Lattice Network JSON RPC
Overview
JSON is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value pairs.
JSON-RPC is a stateless, light-weight remote procedure call (RPC) protocol. Primarily this specification 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.
JavaScript API
To talk to an Lattice Network node from inside a JavaScript application use the web3.js library, which gives an convenient interface for the RPC methods. See the JavaScript API for more.
JSON-RPC Endpoint
Default JSON-RPC endpoints:
Go
You can start the HTTP JSON-RPC with the --rpc
flag
change the default port (8545) and listing address (localhost) with:
If accessing the RPC from a browser, CORS will need to be enabled with the appropriate domain set. Otherwise, JavaScript calls are limit by the same-origin policy and requests will fail:
The JSON RPC can also be started from the geth console using the admin.startRPC(addr, port)
command.
C++
You can start it by running eth
application with -j
option:
You can also specify JSON-RPC port (default is 8080):
JSON-RPC support
JSON-RPC 1.0
✓
JSON-RPC 2.0
✓
✓
Batch requests
✓
✓
HTTP
✓
✓
Output HEX values
At present there are two key datatypes that are passed over JSON: unformatted byte arrays and quantities. Both are passed with a hex encoding, however with different requirements to formatting:
When encoding QUANTITIES (integers, numbers): encode as hex, prefix with "0x", the most compact representation (slight exception: zero should be represented as "0x0"). 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. 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)
Currently cpp-Lattice Network and go-Lattice Network provides JSON-RPC communication only over http.
The default block parameter
The following methods have a extra default block parameter:
When requests are made that act on the state of Lattice Network, 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 numberString "latest"
- for the latest minded blockString "earliest"
for the earliest/genesis blockString "pending"
- for the pending state/transactions
JSON-RPC methods
API
web3_clientVersion
Returns the current client version.
Parameters
none
Returns
String
- The current client version
Example
web3_sha3
Returns SHA3 of the given data.
Parameters
String
- the data to convert into a SHA3 hash
Returns
DATA
- The SHA3 result of the given string.
Example
net_version
Returns the current network protocol version.
Parameters
none
Returns
String
- The current network protocol version
Example
net_listening
Returns true
if client is actively listening for network connections.
Parameters
none
Returns
Boolean
- true
when listening, otherwise false
.
Example
net_peerCount
Returns number of peers currenly connected to the client.
Parameters
none
Returns
QUANTITY
- integer of the number of connected peers.
Example
eth_protocolVersion
Returns the current Lattice Network protocol version.
Parameters
none
Returns
String
- The current Lattice Network protocol version
Example
eth_coinbase
Returns the client coinbase address.
Parameters
none
Returns
DATA
, 20 bytes - the current coinbase address.
Example
eth_mining
Returns true
if client is actively mining new blocks.
Parameters
none
Returns
Boolean
- returns true
of the client is mining, otherwise false
.
Example
eth_gasPrice
Returns the current price per gas in wei.
Parameters
none
Returns
QUANTITY
- integer of the current gas price in wei.
Example
eth_accounts
Returns a list of addresses owned by client.
Parameters
none
Returns
Array of DATA
, 20 Bytes - addresses owned by the client.
Example
eth_blockNumber
Returns the number of most recent block.
Parameters
none
Returns
QUANTITY
- integer of the current block number the client is on.
Example
eth_getBalance
Returns the balance of the account of given address.
Parameters
DATA
, 20 Bytes - address to check for balance.QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Returns
QUANTITY
- integer of the current balance in wei.
Example
eth_getStorageAt
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.QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Returns
DATA
- the value at this storage position.
Example
eth_getTransactionCount
Returns the number of transactions send from a address.
Parameters
DATA
, 20 Bytes - address.QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Returns
QUANTITY
- integer of the number of transactions send from this address.
Example
eth_getBlockTransactionCountByHash
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
eth_getBlockTransactionCountByNumber
Returns the number of transactions in a block from a block matching the given block number.
Parameters
QUANTITY
- integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter
Returns
QUANTITY
- integer of the number of transactions in this block.
Example
eth_getUncleCountByBlockHash
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
eth_getUncleCountByBlockNumber
Returns the number of uncles in a block from a block matching the given block number.
Parameters
QUANTITY
- integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter
Returns
QUANTITY
- integer of the number of uncles in this block.
Example
eth_getCode
Returns code at a given address.
Parameters
DATA
, 20 Bytes - addressQUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Returns
DATA
- the code from the given address.
Example
eth_sendTransaction
Creates new message call transaction or a contract creation, if the data field contains code.
Parameters
Object
- The transaction objectfrom
:DATA
, 20 Bytes - The address the transaction is send from.to
:DATA
, 20 Bytes - (optional when creating new contract) The address the transaction is directed to.gas
:QUANTITY
- (optional, default: To-Be-Determined) 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 payed gasvalue
:QUANTITY
- (optional) Integer of the value send with this transactiondata
:DATA
- (optional) The compiled code of a contract
Returns
DATA
, 20 Bytes - the address of the newly created contract, or the 32 Bytes transaction hash.
Example
eth_call
Executes a new message call immediately without creating a transaction on the block chain.
Parameters
Object
- The transaction call objectfrom
:DATA
, 20 Bytes - The address the transaction is send from.to
:DATA
, 20 Bytes - The address the transaction is directed to.gas
:QUANTITY
- (optional) Integer of the gas provided for the transaction execution. It will return unused gas.gasPrice
:QUANTITY
- (optional) Integer of the gasPrice used for each payed gasvalue
:QUANTITY
- (optional) Integer of the value send with this transactiondata
:DATA
- (optional) The compiled code of a contract
QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
See: eth_sendTransaction Parameters
Returns
DATA
- the return value of executed contract.
Example
eth_getBlockByHash
Returns information about a block by hash.
Parameters
DATA
, 32 Bytes - Hash of a block.Boolean
- Iftrue
it returns the full transaction objects, iffalse
only the hashes of the transactions.
Returns
Object
- A block object, or null
when no transaction was found:
number
:QUANTITY
- the block number.hash
:DATA
, 32 Bytes - hash of the block.parentHash
:DATA
, 32 Bytes - hash of the parent block.nonce
:DATA
, 8 Bytes - hash of the generated proof-of-work.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.transactionsRoot
:DATA
, 32 Bytes - the root of the transaction trie of the blockstateRoot
:DATA
, 32 Bytes - the root of the final state 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
eth_getBlockByNumber
Returns information about a block by block number.
Parameters
QUANTITY
- integer of a block number.Boolean
- Iftrue
it returns the full transaction objects, iffalse
only the hashes of the transactions.
Returns
Example
Result see eth_getBlockByHash
eth_getTransactionByHash
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:
hash
:DATA
, 32 Bytes - hash of the transaction.nonce
:QUANTITY
- the number of transactions made by the sender prior to this one.blockHash
:DATA
, 32 Bytes - hash of the block where this transaction was in.null
when the transaction is pending.blockNumber
:QUANTITY
- block number where this transaction was in.null
when the transaction is pending.transactionIndex
:QUANTITY
- integer of the transactions index position in the block.from
:DATA
, 20 Bytes - address of the sender.to
:DATA
, 20 Bytes - address of the receiver.null
when its a contract creation transaction.value
:QUANTITY
- value transferred in Wei.gasPrice
:QUANTITY
- price paid per gas in Wei.gas
:QUANTITY
- gas used.input
:DATA
- the data send along with the transaction.
Example
eth_getTransactionByBlockHashAndIndex
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.
Returns
Example
Result see eth_getTransactionByHash
eth_getTransactionByBlockNumberAndIndex
Returns information about a transaction by block number and transaction index position.
Parameters
QUANTITY
- a block number.QUANTITY
- the transaction index position.
Returns
Example
Result see eth_getTransactionByHash
eth_getUncleByBlockHashAndIndex
Returns information about a uncle of a block by hash and uncle index position.
Parameters
DATA
, 32 Bytes - hash a block.QUANTITY
- the uncle's index position.
Returns
Example
Result see eth_getBlockByHash
Note: An uncle doesn't contain individual transactions.
eth_getUncleByBlockNumberAndIndex
Returns information about a uncle of a block by number and uncle index position.
Parameters
QUANTITY
- a block number.QUANTITY
- the uncle's index position.
Returns
Note: An uncle doesn't contain individual transactions.
Example
Result see eth_getBlockByHash
eth_getCompilers
Returns a list of available compilers in the client.
Parameters
none
Returns
Array
- Array of available compilers.
Example
eth_compileSolidity
Returns compiled solidity code.
Parameters
String
- The source code.
Returns
DATA
- The compiled source code.
Example
eth_compileLLL
Returns compiled LLL code.
Parameters
String
- The source code.
Returns
DATA
- The compiled source code.
Example
eth_compileSerpent
Returns compiled serpent code.
Parameters
String
- The source code.
Returns
DATA
- The compiled source code.
Example
eth_newFilter
Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call eth_getFilterChanges.
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 BytesDATA
topics.
Returns
QUANTITY
- A filter id.
Example
eth_newBlockFilter
Creates a filter object, based on an option string, to notify when state changes (logs). To check if the state has changed, call eth_getFilterChanges.
Parameters
TAG
- The string"latest"
for notifications about new block and"pending"
for notifications about pending transactions.
Returns
QUANTITY
- A filter id.
Example
eth_uninstallFilter
Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additonally Filters timeout when they aren't requested with eth_getFilterChanges for a period of time.
Parameters
QUANTITY
- The filter id.
Returns
Boolean
- true
if the filter was successfully uninstalled, otherwise false
.
Example
eth_getFilterChanges
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
log objects are null
.
For filters created with eth_newFilter
logs are objects with following params:
logIndex
:QUANTITY
- integer of the log index position in the block.transactionIndex
:QUANTITY
- integer of the transactions index position log was created from.transactionHash
:DATA
, 32 Bytes - hash of the transactions this log was created from.blockHash
:DATA
, 32 Bytes - hash of the block where this log was in.null
when the log is pending.blockNumber
:QUANTITY
- the block number where this log was in.null
when the log is pending.address
:DATA
, 32 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 BytesDATA
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 theanonymous
specifier.)
Example
eth_getFilterLogs
Returns an array of all logs matching filter with given id.
Parameters
QUANTITY
- The filter id.
Returns
Example
Result see eth_getFilterChanges
eth_getLogs
Returns an array of all logs matching a given filter object.
Parameters
Object
- the filter object, see eth_newFilter parameters.
Returns
Example
Result see eth_getFilterChanges
eth_getWork
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-hashDATA
, 32 Bytes - the seed hash used for the DAG.DATA
, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.
Example
eth_submitWork
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
db_putString
Stores a string in the local database.
Parameters
String
- Database name.String
- Key name.String
- String to store.
Returns
Boolean
- returns true
if the value was stored, otherwise false
.
Example
db_getString
Returns string from the local database.
Parameters
String
- Database name.String
- Key name.
Returns
String
- The previously stored string.
Example
db_putHex
Stores binary data in the local database.
Parameters
String
- Database name.String
- Key name.DATA
- The data to store.
Returns
Boolean
- returns true
if the value was stored, otherwise false
.
Example
db_getHex
Returns binary data from the local database.
Parameters
String
- Database name.String
- Key name.
Returns
DATA
- The previously stored data.
Example
shh_version
Returns the current whisper protocol version.
Parameters
none
Returns
String
- The current whisper protocol version
Example
shh_post
Sends a whisper message.
Parameters
Object
- The whisper post object:from
:DATA
, 60 Bytes - (optional) The identity of the sender.to
:DATA
, 60 Bytes - (optional) The identity of the receiver. When present whisper will encrypt the message so that only the receiver can decrypt it.topics
:Array of DATA
- Array ofDATA
topics, for the receiver to identify messages.payload
:DATA
- The payload of the message.priority
:QUANTITY
- The integer of the priority in a rang from ... (?).ttl
:QUANTITY
- integer of the time to live in seconds.
Returns
Boolean
- returns true
if the message was send, otherwise false
.
Example
shh_newIdentinty
Creates new whisper identity in the client.
Parameters
none
Returns
DATA
, 60 Bytes - the address of the new identiy.
Example
shh_hasIdentity
Checks if the client hold the private keys for a given identity.
Parameters
DATA
, 60 Bytes - The identity address to check.
Returns
Boolean
- returns true
if the client holds the privatekey for that identity, otherwise false
.
Example
shh_newGroup
(?)
Parameters
none
Returns
DATA
, 60 Bytes - the address of the new group. (?)
Example
shh_addToGroup
(?)
Parameters
DATA
, 60 Bytes - The identity address to add to a group (?).
Returns
Boolean
- returns true
if the identity was successfully added to the group, otherwise false
(?).
Example
shh_newFilter
Creates filter to notify, when client receives whisper message matching the filter options.
Parameters
Object
- The filter options:to
:DATA
, 60 Bytes - (optional) Identity of the receiver. When present it will try to decrypt any incoming message if the client holds the private key to this identity.topics
:Array of DATA
- Array ofDATA
topics which the incoming message's topics should match.
Returns
QUANTITY
- The newly created filter.
Example
shh_uninstallFilter
Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additonally Filters timeout when they aren't requested with shh_getFilterChanges for a period of time.
Parameters
QUANTITY
- The filter id.
Returns
Boolean
- true
if the filter was successfully uninstalled, otherwise false
.
Example
shh_getFilterChanges
Polling method for whisper filters. Returns new messages since the last call of this method.
Note calling the shh_getMessages method, will reset the buffer for this method, so that you won't receive duplicate messages.
Parameters
QUANTITY
- The filter id.
Returns
Array
- Array of messages received since last poll:
hash
:DATA
, 32 Bytes (?) - The hash of the message.from
:DATA
, 60 Bytes - The sender of the message, if a sender was specified.to
:DATA
, 60 Bytes - The receiver of the message, if a receiver was specified.expiry
:QUANTITY
- Integer of the time in seconds when this message should expire (?).ttl
:QUANTITY
- Integer of the time the message should float in the system in seconds (?).sent
:QUANTITY
- Integer of the unix timestamp when the message was sent.topics
:Array of DATA
- Array ofDATA
topics the message contained. You can use the following combinations:[A, B] = A && B
[A, [B, C]] = A && (B || C)
[null, A, B] = ANYTHING && A && B
null
works as a wildcard
payload
:DATA
- The payload of the message.workProved
:QUANTITY
- Integer of the work this message required before it was send (?).
Example
shh_getMessages
Get all messages matching a filter, which are still existing in the node's buffer.
Note calling this method, will also reset the buffer for the shh_getFilterChanges method, so that you won't receive duplicate messages.
Parameters
QUANTITY
- The filter id.
Returns
Example
Result see shh_getFilterChanges
Last updated