Remote Procedure Call (RPC)

RPC API Reference

By default, RPC API listens on 20336 port.

The following option can be used to change the port at which the client side RPC API listens:

ontology --rpcport 1024

The following option can be used to stop the client side RPC service:

ontology --disable-rpc

Remote Procedure Call (RPC), also known as function call or subroutine call, are used on one machine on a network to request services from another machine without the need of detailed network information.

Interface definition

The JSON-RPC interface definition is as follows:

Request parameters

The structure of the request message is as follows:

Field

Data type

Description

jsonrpc

String

JSON-RPC version

method

String

Method name

params

String

Method parameters

id

Integer

Arbitrary value

Method list

Method

Parameters

Description

Note

Get the hash of the highest block for the current node

height or blockhash,[verbose]

Get block by block height or block hash

Verbose can be 0 or 1, response is different

Get the number of blocks

height

Get block hash by block height

Get the current number of connections for the node

transactionhash

Returns the corresponding transaction information based on the specified hash value.

hex,preExec

Broadcast transaction.

Serialized signed transactions constructed in the program into hexadecimal strings

script_hash, key

Returns the stored value according to the contract address hash and storage key.

Get the version information of the node

script_hash,[verbose]

According to the contract address hash, query the contract information.

Query the transaction count in the memory pool.

tx_hash

Query the transaction state in the memory pool.

Get smartcode event

tx_hash

Get blockheight of transaction hash

address

Fetch the balance of base58 account address.

getbalancev2

address

tx_hash

Fetch merkle proof

Fetch gasprice

asset, from, to

Return the allowance from the from account to the to account

asset, from, to

Return the allowance from the from account to the to account, with ONT's decimals being 9, a ONG's decimals being 18

address

Fetch the amount of unbound ong

height

Fetch the transaction hashes

Get the network id

Get grant ong

getsyncstatus

Fetch the synchronization status of the node

Response parameters

The structure of the response message after a request is sent is as follows:

Field

Data type

Description

desc

String

Request result description

error

Integer

Error code

jsonrpc

String

JSON-RPC version

id

Integer

Arbitrary value

result

JSON object

RPC execution result

getbestblockhash

Fetch block hash for the highest block for the current node.

Sample request

Sample response

getblock

Fetch block details using block hash or block height.

Sample request - using block hash

Sample response

Sample request - using block height

Sample response

getblockcount

Fetch current block count.

Sample request

Sample response

getblockhash

Fetch the block hash for the block at given block height.

Sample request

Sample response

getconnectioncount

The no. of nodes connected to the current network.

Sample request

Sample response

getrawtransaction

Fetch transaction details using transaction hash.

Sample request - non verbose

Sample response

Sample response - verbose

Sample response

sendrawtransaction

Transmit a transaction to the network.

Sample request

Sample response

The result field contains the transaction hash.

getstorage

Fetched the stored value using contract hash and the storage key.

Sample request

Sample response

The storage key is a hexadecimal string.

The result is also a serialized hex string. It can be deserialized using the SDK.

The contract address can be generated from the AVM code using SDK methods.

Python SDK

Go SDK

Java SDK

getversion

Fetch the version of the current node.

Sample request

Sample response

getcontractstate

Fetch contract details using contract address.

Sample request

Sample response

getmempooltxcount

Fetch the no. of transactions in the node memory pool.

Sample request

Sample response

getmempooltxstate

Fetch state of transaction in the node memory pool using given transaction hash.

Sample request

Sample response

getsmartcodeevent

Fetch smart contract execution result using block height or transaction hash.

Sample request - using block height

Sample response

Sample request - using transaction hash

Sample response

Response parameters

Field

Description

TxHash

Transaction hash

State

Transaction execution status, 0 indicates execution failure, 1 indicates execution success

GasConsumed

Amount of gas consumed for execution

Notify

Contract events triggered by the transaction

The two fields within Notify:

Field

Description

ContractAddress

Contract address where the event occurred

States

Event details

When the block height is passed as the parameter, the response contains the list of all the transactions that are the execution result.

When a transaction hash is passed as the parameter, the response contains the execution result of the particular transaction.

The States field specified in the Notify field is a hex string in for single transactions, and an array for multiple transactions.

getblockheightbytxhash

Fetch the block height for the block in which a particular transaction is recorded using transaction hash.

Sample request

Sample response

getbalance

Fetch the current balance of a Base58 address.

Sample request

Sample response

getbalancev2

Return the allowance from the from account to the to account, with ONT's decimals being 9, a ONG's decimals being 18.

Sample request

Sample response

getmerkleproof

Fetches the merkle proof for a transaction using given transaction hash.

Sample request

Sample response

getgasprice

Fetch current gas price.

Sample request

Sample response

getallowance

Fetch the amount of a given asset allocated as allowance to an address.

Sample request

Sample response

getallowancev2

return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18

Sample request

Sample response

getgrantong

Fetch the amount of granted ONG.

Sample request

Sample response

getunboundong

Fetch the amount of unbound ONG that can be withdrawn for a particular address.

Sample request

Sample response

getblocktxsbyheight

Fetches transaction hashes of all the transactions in the block at a given height.

Sample request

Sample response

getnetworkid

Fetch the network ID of the current network.

Sample request

Sample response

Error codes

The error codes in the response message signify the following:

Field

Data type

Description

0

int64

Success

41001

int64

Session timeout or invalid

41002

int64

Service limit reached

41003

int64

Invalid data format

41004

int64

Invalid version number

42001

int64

Invalid function

42002

int64

Invalid parameter

43001

int64

Invalid transaction

43002

int64

Invalid resource

43003

int64

Invalid block

44001

int64

Unknown transaction

44002

int64

Unknown resource

44003

int64

Unknown block

45001

int64

Internal error

47001

int64

Smart contract execution error

Last updated