JSON RPC API
Contents
JSON RPC API
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.
gabey has experimental pub/sub support. See this page for more information.
JSON-RPC Endpoint
Default JSON-RPC endpoints: http://localhost:8545
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:
JSON-RPC support
JSON-RPC 2.0/ Batch requests/ HTTP/ IPC/ WS
The default block parameter
The following methods have an extra default block parameter:
When requests are made that act on the state of abeychain, 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 blockString "latest"
- for the latest mined blockString "pending"
- for the pending state/transactions
Curl Examples Explained
The curl options below might return a response where the node complains about the content type, this is because the --data option sets the content type to application/x-www-form-urlencoded . If your node does complain, 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.x. 127.0.0.1:8545
JSON-RPC methods
-
JSON RPC API Reference
web3
web3_clientVersion
Returns the current client version.
Parameters
none
Returns
String
- The current client version.
Example
web3_sha3
Returns Keccak-256 (not the standardized SHA3-256) of the given data.
Parameters
DATA
- the data to convert into a SHA3 hash.
Example Parameters
Returns
DATA
- The SHA3 result of the given string.
Example
net
net_version
Returns the current network id.
Parameters
none
Returns
String
- The current network id.
"19330"
: abeychain Mainnet"18928"
: Testnet"100"
: Devnet
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 currently connected to the client.
Parameters
none
Returns
QUANTITY
- integer of the number of connected peers.
Example
ABEY
abey_protocolVersion
Returns the current abeychain protocol version.
Parameters
none
Returns
String
- The current abeychain protocol version.
Example
abey_syncing
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:
currentFastBlock
:QUANTITY
-current block number(fastchain)currentSnailBlock
:QUANTITY
-current block number(snailchain)highestFastBlock
:QUANTITY
- already highest block number(fastchain)highestSnailBlock
:QUANTITY
-already highest block number(snailchain)knownStates
:String
-already know statepulledStates
:String
-already complete statestartingFastBlock
:QUANTITY
-start sync block number(fastchain)startingSnailBlock
:QUANTITY
-start sync block number(snailchain)
Example
abey_coinbase
Returns the client coinbase address.
Parameters
none
Returns
DATA
, 20 bytes - the current coinbase address.
Example
abey_mining
Returns true
if client is actively mining new blocks.
Parameters
none
Returns
Boolean
- returns true
of the client is mining, otherwise false
.
Example
abey_hashrate
Returns the number of hashes per second that the node is mining with.
Parameters
none
Returns
QUANTITY
- number of hashes per second.
Example
abey_gasPrice
Returns the current price per gas in wei.
Parameters
none
Returns
QUANTITY
- integer of the current gas price in wei.
Example
abey_accounts
Returns a list of addresses owned by client.
Parameters
none
Returns
Array of DATA
, 20 Bytes - addresses owned by the client.
Example
abey_blockNumber
Returns the number of most recent block.
Parameters
none
Returns
QUANTITY
- integer of the current block number the client is on.
Example
abey_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
Example Parameters
Returns
QUANTITY
- integer of the current balance in wei.
Example
abey_getLockBalance
Returns the locked 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
Example Parameters
Returns
QUANTITY
- integer of the current balance in wei.
Example
abey_getTotalBalance
Returns the total 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
Example Parameters
Returns
QUANTITY
- integer of the current balance in wei.
Example
abey_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
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 gabey console which comes with the web3 library can be used to make the calculation:
Now to fetch the storage:
abey_getTransactionCount
Returns the number of transactions sent from an address.
Parameters
DATA
, 20 Bytes - address.QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Example Parameters
Returns
QUANTITY
- integer of the number of transactions send from this address.
Example
abey_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.
Example Parameters
Returns
QUANTITY
- integer of the number of transactions in this block.
Example
abey_getBlockTransactionCountByNumber
Returns the number of transactions in a block matching the given block number.
Parameters
QUANTITY|TAG
- integer of a block number, or the string"earliest"
,"latest"
or"pending"
, as in the default block parameter.
Example Parameters
Returns
QUANTITY
- integer of the number of transactions in this block.
Example
abey_getCode
Returns code at a given address.
Parameters
DATA
, 20 Bytes - address.QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter.
Example Parameters
Returns
DATA
- the code from the given address.
Example
abey_sign
The sign method calculates an abeychain specific signature with: sign(keccak256("\x19abeychain Signed Message:\n" + len(message) + message)))
.
By adding a prefix to the message makes the calculated signature recognisable as an abeychain 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
account, message
DATA
, 20 Bytes - address.DATA
, N Bytes - message to sign.
Returns
DATA
: Signature
Example
An example how to use solidity ecrecover to verify the signature calculated with abey_sign
can be found here. The contract is deployed on the testnet Ropsten and Rinkeby.
abey_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: 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 gasvalue
:QUANTITY
- (optional) Integer of the value sent with this transactiondata
: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.
Example Parameters
Returns
DATA
, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Use abey_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example
abey_sendRawTransaction
Creates new message call transaction or a contract creation for signed transactions.
Parameters
DATA
, The signed transaction data.
Example Parameters
Returns
DATA
, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Use abey_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example
abey_sendAbeyRawTransaction
When transaction contain payer or fee,Creates new message call transaction or a contract creation for signed transactions.
Parameters
DATA
, The signed transaction data.
Example Parameters
Returns
DATA
, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Use abey_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example
abey_call
Executes a new message call immediately without creating a transaction on the block chain.
Parameters
Object
- The transaction call objectfrom
: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. abey_call consumes zero gas, but this parameter may be needed by some executions.gasPrice
:QUANTITY
- (optional) Integer of the gasPrice used for each paid gasvalue
:QUANTITY
- (optional) Integer of the value sent with this transactiondata
:DATA
- (optional) Hash of the method signature and encoded parameters
QUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
or"pending"
, see the default block parameter
Returns
DATA
- the return value of executed contract.
Example
abey_estimateGas
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
See abey_call parameters, expect that all properties are optional. If no gas limit is specified gabey 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.
Returns
QUANTITY
- the amount of gas used.
Example
abey_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.
Example Parameters
Returns
Object
- A block object, or null
when no block was found:
SnailHash
:DATA
, 32 Bytes - hash of the snail block.SnailNumber
:QUANTITY
- the snail block number.committeeRoot
:DATA
, 32 Bytes - hash of the committtee.extraData
:DATA
- the "extra data" field of this block.gasLimit
:QUANTITY
- the maximum gas allowed in this block.gasUsed
:QUANTITY
- the total used gas by all transactions in this block.hash
:DATA
, 32 Bytes - hash of the block.null
when its pending block.logsBloom
:DATA
, 256 Bytes - the bloom filter for the logs of the block.null
when its pending block.maker
:DATA
, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.number
:QUANTITY
- the block number.null
when its pending block.parentHash
:DATA
, 32 Bytes - hash of the parent block.receiptsRoot
:DATA
, 32 Bytes - the root of the receipts trie of the block.signs
:Array
, committee signs.fastHash
:DATA
, 32 Bytes - hash of the fast block.fastHeight
:QUANTITY
- the fast block number.result
:QUANTITY
- the vote.sign
:DATA
, 32 Bytes - committee sign hash.
size
:QUANTITY
- integer the size of this block in bytes.stateRoot
:DATA
, 32 Bytes - the root of the final state trie of the block.switchInfos
:Array
, committee member switch.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.transactionsRoot
:DATA
, 32 Bytes - the root of the transaction trie of the block.
Example
abey_getBlockByNumber
Returns information about a block by block number.
Parameters
QUANTITY|TAG
- integer of a block number, or the string"earliest"
,"latest"
or"pending"
, as in the default block parameter.Boolean
- Iftrue
it returns the full transaction objects, iffalse
only the hashes of the transactions.
Example Parameters
Returns
Example
Result see abey_getBlockByHash
abey_getTransactionByHash
Returns the information about a transaction requested by transaction hash.
Parameters
DATA
, 32 Bytes - hash of a transaction
Example Parameters
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 transaction's index position in the block.null
when its pending.value
:QUANTITY
- value transferred in Wei.v
:QUANTITY
- ECDSA recovery idr
:DATA
, 32 Bytes - ECDSA signature rs
:DATA
, 32 Bytes - ECDSA signature spayer
:DATA
, 20 Bytes - address of the payer.fee
:QUANTITY
- transaction fee in Wei.pv
:QUANTITY
- ECDSA recovery idpr
:DATA
, 32 Bytes - ECDSA signature prps
:DATA
, 32 Bytes - ECDSA signature ps
Example
abey_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.
Example Parameters
Returns
Example
Result see abey_getTransactionByHash
abey_getTransactionByBlockNumberAndIndex
Returns information about a transaction by block number and transaction index position.
Parameters
QUANTITY|TAG
- a block number, or the string"earliest"
,"latest"
or"pending"
, as in the default block parameter.QUANTITY
- the transaction index position.
Example Parameters
Returns
Example
Result see abey_getTransactionByHash
abey_getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
Note