WebSocket
Websocket API Reference
Last updated
Websocket API Reference
Last updated
By default, Websocket API
listens on 20335
port.
After a local node has been installed, Websocket
can be started on the client end using the following command:
The following option can be used to change the port at which the Websocket API
listens:
Ontology's client side Websocket
interface has been standardized as follows:
The structure of the response message after a request is sent is as follows:
The methods available as a part of the Websocket API
to query the chain:
heartbeat
Sends heartbeat information. If heartbeat information is not received by the client the sessin expires in 5 minutes.
subscribe
Used to subscribe to a particular service.
getconnectioncount
Fetches the number of connections to the node.
getblocktxsbyheight
Fetch transaction hashes for a block at given height.
getblockbyheight
Fetch block details for block at given height.
getblockbyhash
Fetch block details for block using given block hash.
When the value of the raw
field in the request is set to 1, the API returns serialized block information in the form of a hex string. For 0, it returns raw information in the form of a JSON string. The default value is 0.
getblockheight
Fetch the current block height.
getblockhash
Fetch block hash for the block at given height.
gettransaction
Fetch transaction details for a transaction using given hash.
When the value of the raw
field in the request is set to 1, the API returns serialized transaction information in the form of a hex string. For 0, it returns raw information in the form of a JSON string. The default value is 0.
sendrawtransaction
Send a raw transaction to be recorded on the chain.
The PreExec
field in the request object is used to specify whether the contract needs to be pre-run. If the contract is to be pre-run, set the value to 1, else 0.
The result obtained is the transaction hash of the raw transaction.
getstorage
Fetches the value stored in a contract using the contract hash and the storage key.
The contract hash passed to the method can be generated in the following manner:
The result
in the response object and the key
in the request are hex strings
getbalance
Fetches the balance of a Base58 address.
getbalancev2
Fetch the balance of the account using an address, with ONT's decimals being 9, a ONG's decimals being 18
getcontract
Fetches the contract details for the contract using given contract hash.
Sample request
getsmartcodeeventbyheight
Fetches event details for a smart contract event that occurred at given block height and fetches the transaction list.
Sample request
Sample response
The result
in the response object is a list that contains transaction hashes
getsmartcodeeventbyhash
Fetch contract event details using given transaction hash.
Sample request
getblockheightbytxhash
Fetch block height using given transaction hash.
Sample request
getmerkleproof
Fetch merkle proof for given block hash.
getsessioncount
Fetch session count.
Sample response
getgasprice
Fetch gas price.
Sample response
getallowance
Fetch the amount of allowance of a certain asset granted by one address to another address.
getallowancev2
Return the allowance from the from account to the to account, with ONT's decimals being 9, a ONG's decimals being 18.
Sample response
getunboundong
Fetch amount of unbound ONG for an address.
getmempooltxstate
Fetches state of transactions in the memory pool.
getmempooltxcount
Fetch the transaction count in the memory pool.
getversion
Fetch version details for a node.
getnetworkid
Fetch the network ID.
Sample response
getgrantong
Fetch the granted ONG for an address.
getsyncstatus
Fetch the synchronization status of the node.
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 |
Field | Data type | Description |
Action | String | Response action name |
Desc | String | Response result description |
Error | Integer | Error code |
Result | Object | Execution result |
Version | String | Version number |
Id | int64 | Request ID |
Method | Description |
Send the heartbeat information |
Subscribe to a particular service |
Fetch the number of nodes in the network |
Fetch all the transaction hashes for a block at a given height |
Fetch the block details for a block at a given height |
Fetch the block details using the block hash |
Fetch the current block height of the blockchain |
Fetch the block hash for a block at a given height |
Fetch the transaction details using a given transaction hash |
Send a transaction to the Ontology network, if |
Fetch the corresponding value using the contract address hash or the key |
Fetch the balance of the account using an address |
Fetch the balance of the account using an address, with ONT's decimals being 9, a ONG's decimals being 18 |
Fetch the contract status using the contract address hash |
Fetch the contract execution result for a particular block using the block height |
Fetch transaction execution result using a given transaction hash |
Fetch the block height at which a transaction was carried out using a given transaction hash |
Fetch the |
Fetch current session count on the server side |
Fetch the gas price |
Return the allowance from the |
getallowancev2 | Return the allowance from the |
Return the unclaimed |
Fetch the transaction status for a given transaction using the transaction hash |
Fetch the number of transactions stored in the memory |
Fetch the version information |
Fetch the |
Fetch the |
Fetch the synchronization status of the node |