JSON-RPC
To interact with the Hash Ahead blockchain, such as reading blockchain data or sending transaction information to the network, a software application must connect to a Hash Ahead node.
For this purpose, each Hash Ahead client implements a JSON-RPC specification, so there is a unified set of methods available for applications to rely on, regardless of the specific node or client implementation.
JSON-RPCJSON-RPC is a stateless, lightweight remote procedure call (RPC) protocol. It defines some data structures and their processing rules. It is transport-independent as these concepts can be used in the same process, via interfaces, hypertext transfer protocol, or many different messaging environments. It uses JSON (RFC 4627) as the data format.
Although you can choose to interact directly with Hash Ahead clients through the JSON Application Programming Interface (API), there are often easier options for decentralized application developers. Many existing JavaScript and backend API libraries offer wrappers over the JSON-RPC API. With these libraries, developers can conveniently write a single line function to initialize (backend) JSON RPC requests and use them to interact with Hash Ahead.
JSON-RPC application interface methods
web3_clientVersion
Returns the current client version.
return value
String - current client version
示例:
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}'
// Result
{
"id":67,
"jsonrpc":"2.0",
"result": "Mist/v0.9.3/darwin/go1.4.1"
}eweb3_sha3
Returns the Keccak-256 (not standardized SHA3-256) hash of the given data.
return value
DATA - The SHA3 result of a given string.
Example:
net_version
Returns the current network id.
return value
String - current network id.
Example:
net_listening
Returns true if the client is actively listening for network connections.
return value
Boolean - It returns true if the client is actively listening for network connections, otherwise it returns false.
Example:
net_peerCount
Returns the number of peers currently connected to the client.
return value
QUANTITY - This is an integer representing the number of connected peers to the client.
Example:
eth_protocolVersion
Returns the current Hash Ahead protocol version.
return value
String - The current Hash Ahead protocol version.
Example:
eth_syncing
Returns an object containing data about the sync state or false.
return value
Object|Boolean,object with synchronized state data,or FALSE(when out of sync):
startingBlock:QUANTITY- import start block(It will only be reset when the sync reaches the head of the chain)currentBlock:QUANTITY- current block, same as eth_blockNumberhighestBlock:QUANTITY- Estimated Highest Block
Example:
eth_coinbase
Returns the client coinbase address.
return value
DATA,20 bytes - current coinbase address.
Example:
eth_coinbase
Returns the client coinbase address.
return value
DATA,20 bytes - current coinbase address.
Example:
eth_mining
Returns true if the client is actively mining new blocks.
return value
Boolean - Returns true if the client is mining, false otherwise.
Example:
eth_hashrate
Returns the number of hashes per second used by the node for mining.
return value
QUANTITY - hashes per second.
Example:
eth_gasPrice
Returns the current price per unit of gas in wei.
return value
QUANTITY - The integer representing the current fuel price in wei.
Example:
eth_accounts
Returns a list of addresses owned by the client.
return value
Array of DATA,20 bytes - Address owned by the client.
Example:
eth_getBalance
Return the account balance of the given address.
return value
QUANTITY - An integer representing the current balance in wei.
Example:
eth_blockNumber
Return the number of recent blocks.
return value
QUANTITY - An integer showing the block number of the current area where the client terminal is located.
Example:
eth_getStorageAt
Return the value from storage at the given address.
return value
DATA - The value of this storage location.
Example:
To retrieve the value of a storage location, the correct position needs to be calculated based on the storage being retrieved. Consider the following contract deployed at address 0x295a70b2de5e3953354a6a8344e616ed314d7251 with the address 0x391694e7e0b0cce554cb130d723a9d27458f9298.
Retrieving the value of 'pos0' is straightforward:
eth_getTransactionCount
Returns the number of transactions sent from a specified address.
return value
QUANTITY - The integer representing the number of transactions sent from the given address.
Example:
eth_getBlockTransactionCountByHash
Return the number of transactions in the block matching the given block hash.
return value
QUANTITY - An integer representing the number of transactions in this block.
Example:
eth_getBlockTransactionCountByNumber
Returns the number of transactions in the block matching the given block number.
return value
QUANTITY - An integer representing the number of transactions in this block.
Example:
eth_getUncleCountByBlockHash
Returns the number of uncles in the block from blocks matching the given block hash.
return value
QUANTITY - Integer representing the number of uncle blocks in this block.
Example:
eth_getUncleCountByBlockNumber
Returns the number of uncles in the block matching the given block number.
return value
QUANTITY - An integer representing the number of uncle blocks in this block.
Example:
eth_getCode
Return the code located at the given address.
return value
DATA - Code from the given address.
Example:
eth_sign
The Sign method calculates the Hash Ahead-specific signature: sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))).
By adding a prefix to the message, the calculated signature can be identified as a Hash Ahead-specific signature. This prevents malicious decentralized applications from signing arbitrary data (such as transactions) and abusing signatures to impersonate victims.
Note: the address to be signed must be unlocked.
return value
DATA:sign
Example:
eth_signTransaction
Signs a transaction and returns the signed transaction data, which can then be submitted to the network using ’eth_sendRawTransaction‘.
parameter
Object- Trading partners
from:DATA,20 bytes - the address to send the transaction from.to:DATA,20 bytes - (optional when creating a new contract) the address to direct the transaction to.gas:QUANTITY-(Optional, default: 90000) Integer representing the gas provided for transaction execution. It will return unused fuel.gasPrice:QUANTITY-Optional, default value: to be determined. An integer representing the gas price in Wei to be used for each unit of gas paid.value:QUANTITY-(Optionally) An integer representing the value (in Wei) sent with this transaction.data:DATA- This is the hash of the compiled code of a contract or the method signature and encoded parameters of a method call.nonce:QUANTITY-(Optional)An integer representing the random number. This allows overwriting a pending transaction that uses the same random number.
return value
DATA,Signed transaction object.
Example:
eth_sendTransaction
If the data field contains code, creates a new message call transaction or a contract creation.
parameter
Object- The transaction objectfrom: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.
Use eth_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example:
eth_sendRawTransaction
Creates new message call transaction or a contract creation for signed transactions.
Returns
DATA, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Use eth_getTransactionReceipt to get the contract address, after the transaction was mined, when you created a contract.
Example
eth_call
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 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"
Returns
DATA - the return value of executed contract.
Example
eth_estimateGas
Generates and returns an estimate of the amount of gas required to allow the transaction to complete. Transactions are not added to the blockchain. Note that estimates may far exceed the actual amount of gas used by a transaction for various reasons, including Ethereum Virtual Machine mechanics and node performance.
return value
QUANTITY - 使用的燃料数量。
Example
eth_getBlockByHash
Returns information about a block based on a hash.
return value
Object - block object,or null(when no block is found):
number:QUANTITY- block number. null when it is a pending block.hash:DATA,32 bytes - hash of the block. It is null when it is a pending block.parentHash:DATA,32 bytes - Hash of the parent block.nonce:DATA,8 bytes - Hash of generated proof of work. It is null when it is a pending block.sha3Uncles:DATA,32 bytes - SHA3 of the uncle data in the block.logsBloom:DATA,256 bytes - Bloom filter for the block log. It is null when it is a pending block.transactionsRoot:DATA,32 bytes - The root of the block's transaction prefix tree.stateRoot:DATA,32 bytes - The root of the block's final state prefix tree.receiptsRoot:DATA,32 bytes - Root of block receipt prefix tree.miner:DATA,20 bytes - the address of the beneficiary who received the mining reward.difficulty:QUANTITY- An integer representing the difficulty of this block.totalDifficulty:QUANTITY- An integer representing the total difficulty of the chain up to this block.extraData:DATA- "Additional Data" field for this block.size:QUANTITY- An integer representing the size of this chunk, in bytes.gasLimit:QUANTITY- The maximum allowable fuel value for this block.gasUsed:QUANTITY- The total amount of fuel used by all transactions in this block.timestamp:QUANTITY- The unix timestamp when the block was collated.transactions:Array- An array of transaction objects, or a 32 byte transaction hash, depending on the last given parameter.uncles:Array- Tertiary block hash array.
Example
eth_getBlockByNumber
Retrieve information about a block based on its block number.
See return values: eth_getBlockByHash
Example
eth_getTransactionByHash
Returns information about the requested transaction based on the transaction hash.
return values
Object - The transaction object, or null if no transaction was found:
blockHash:DATA,32 bytes - The hash of the block this transaction is in. It is null when it is a pending block.blockNumber:QUANTITY- The block number that this transaction is in. It will be null when it is in the pending state.from:DATA,20 bytes - sender's address.gas:QUANTITY- The gas provided by the sender.gasPrice:QUANTITY- The gas price offered by the sender, in Wei.hash:DATA,32 bytes - Hash of the transaction.input:DATA- The data sent with the transaction.nonce:QUANTITY- The number of transactions the sender made prior to this transaction.to:DATA,20 bytes - the address of the recipient. Or null when it is a contract creation transaction.transactionIndex:QUANTITY- Integer representing the index position of the transaction in the block. It is null when it is a pending block.value:QUANTITY- The value of the transfer, in Wei.v:QUANTITY- ECDSA Recovery IDr:QUANTITY- ECDSA signature rs:QUANTITY- ECDSA signature s
Example
eth_getTransactionByBlockHashAndIndex
Returns information about a transaction based on the block hash and transaction index position.
See return values: eth_getTransactionByHash
Example
eth_getTransactionByBlockNumberAndIndex
Returns information about a transaction based on the block number and transaction index position.
See return values eth_getTransactionByHash
Example
eth_getTransactionReceipt
Returns a receipt for a transaction based on the transaction hash.
Note: Receipts are not available for pending transactions.
Return Value Object - The transaction receipt object, or null if no receipt was found:
transactionHash:DATA,32 bytes - Hash of the transaction.transactionIndex:QUANTITY- Integer representing the index position of the transaction in the block.blockHash:DATA,32 bytes - The hash of the block this transaction is in.blockNumber:QUANTITY- The block number this transaction is in.from:DATA,20 bytes - sender's address.to:DATA,20 bytes - the address of the recipient. Or null when it is a contract creation transaction.cumulativeGasUsed:QUANTITY- The total amount of gas used when executing this transaction in the block.gasUsed:QUANTITY- The amount of gas used by this particular transaction only.contractAddress:DATA,20 bytes - If the transaction is a contract creation, the created contract address, otherwise null.logs:Array- An array of log objects generated by this transaction.logsBloom:DATA,256 characters - Bloom filter used by light clients to quickly retrieve related logs. It also returns one of the following:root:DATA32 byte post-transaction stateroot (pre-Byzantine)status:QUANTITY-1(success)或0(fail)
Example
eth_getUncleByBlockHashAndIndex
Returns information about the block's uncle based on the hash and uncle index position.
See return values: eth_getBlockByHash
Example
eth_getUncleByBlockNumberAndIndex
Returns information about a region's uncles based on number and uncle search position.
See return values: eth_getBlockByHash
Note: Uncles do not contain individual transactions.
Example
Last updated