Web3 API
Web3 protocol API to interact with Ontology
Since the structure of transactions on Ontology is different from those on Ethereum, Ontology currently supports the methods listed and described below.
Method List
Method Name
Description
Returns the current network ID
Returns the current chainId
Returns the number of most recent block
Returns the balance of the account of given address
Returns the current Ethereum protocol version
Returns data about the sync status
Returns the current price per gas in wei
Returns the value from a storage position at a given address
Returns the number of transactions sent from an address using Ontology EVM
Returns the number of transactions using Ontology EVM in a block from a block matching the given block hash
Returns the number of transactions in a block matching the given block number
Returns code at a given address
Returns transaction logs by a transaction hash
Creates new message call transaction or a contract creation for signed transactions
Executes a new message call immediately without creating a transaction on the blockchain
Generates and returns an estimate of gas
Returns information about a block by block number
Returns information about a block by hash
Returns information about a transaction by block hash
Returns information about a transaction by block hash and transaction index position
Returns information about a transaction by block number and transaction index position
Returns the receipt of a transaction by transaction hash
Access all pending transactions
Access all pending transactions by transaction hash
net_version
net_version
Returns the current network ID.
Parameters
None
Returns
String
- The current network ID
58
- Ontology Mainnet5851
- Ontology Polaris Testnet12345
- Solo node
Sample Request
Sample Response
eth_chainId
eth_chainId
Returns the current chainId
.
Parameters
None
Returns
String
- the current chainId
Sample Request
Sample Response
eth_blockNumber
eth_blockNumber
Returns the number of most recent block.
Parameters
None
Returns
QUANTITY
- integer of the current block number the client is on
Sample Request
Sample Response
eth_getBalance
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"
Returns
QUANTITY
- integer of the current balance in wei.
Sample Request
Sample Response
eth_protocolVersion
eth_protocolVersion
Returns the current Ethereum protocol version.
Parameters
None
Returns
String
- The current Ethereum protocol version
Sample Request
Sample Response
eth_syncing
eth_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. Object structure:
startingBlock
:QUANTITY
- The block at which the import startedcurrentBlock
:QUANTITY
- The current block, same aseth_blockNumber
highestBlock
:QUANTITY
- The estimated highest block
Sample Request
Sample Response
eth_gasPrice
eth_gasPrice
Returns the current price per gas in wei.
Parameters
None
Returns
QUANTITY
- integer of the current gas price in wei.
Sample Request
Sample Response
eth_getStorageAt
eth_getStorageAt
Returns the value from a storage position at a given address.
Parameters
DATA
, 20 Bytes - address of the storageQUANTITY
- integer of the position in the storageQUANTITY|TAG
- integer block number, or the string"latest"
,"earliest"
orpending"
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:
Sample Response
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 geth console which comes with the web3 library can be used to make the calculation:
Now to fetch the storage:
Sample Response
eth_getTransactionCount
eth_getTransactionCount
Returns the number of transactions sent from an address using Ontology EVM.
Parameters
DATA
, 20 Bytes - address.QUANTITY|TAG
integer block number, or the string"latest"
,"earliest"
or"pending"
Returns
QUANTITY
- integer of the number of transactions send from this address
Sample Request
Sample Response
eth_getBlockTransactionCountByHash
eth_getBlockTransactionCountByHash
Returns the number of transactions using Ontology EVM 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
Sample Request
Sample Response
eth_getBlockTransactionCountByNumber
eth_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"
.
Returns
QUANTITY
- integer of the number of transactions in this block
Sample Request
Sample Response
eth_getCode
eth_getCode
Returns code at a given address.
Parameters
DATA
, 20 Bytes - address.QUANTITY|TAG
- integer of a block number, or the string"earliest"
,"latest"
or"pending"
(Invalid Parameter).
Returns
DATA
- the code from the given address
Sample Request
Sample Response
eth_getTransactionLogs
eth_getTransactionLogs
Returns transaction logs by a transaction hash.
Parameters
txHash
- transaction hash
Returns
Sample Request
Sample Response
eth_sendRawTransaction
eth_sendRawTransaction
Creates new message call transaction or a contract creation for signed transactions.
Parameters
DATA
- The signed transaction data
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.
Sample Request
Sample Response
eth_call
eth_call
Executes a new message call immediately without creating a transaction on the blockchain.
Parameters
Object
- The transaction call object:
from
:DATA
,20 Bytes, 20 Bytes - (optional) The address the transaction is sent from.to
:DATA
, 20 Bytes, 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 gas.value
:QUANTITY
- (optional) Integer of the value sent with this transaction.data
:DATA
- (optional) Hash of the method signature and encoded parameters.QUANTITY|TAG
- integer of a block number, or the string"earliest"
,"latest"
or"pending"
.
Returns
DATA
- the return value of executed contract.
Sample Request
Sample Response
eth_estimateGas
eth_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 eth_call
parameters. All properties are optional. If no gas limit is specified geth uses the block gas limit from the pending block as an upper bound. As a result the returned estimate might not be enough to execute the call/transaction when the amount of gas is higher than the pending block gas limit.
Returns
QUANTITY
- the estimated amount of gas.
Sample Request
Sample Response
eth_getBlockByNumber
eth_getBlockByNumber
Returns information about a block by block number.
Parameters
QUANTITY|TAG
- integer of a block number, or the string"earliest"
,"latest"
or"pending"
.Boolean
- Iftrue
it returns the full transaction objects, iffalse
only the hashes of the transactions.
Returns
Object
- A block object, or null
when no block 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 - nulllogsBloom
:DATA
, 256 Bytes - nulltransactionsRoot
:DATA
, 32 Bytes - the root of the transaction tree of the block.stateRoot
:DATA
, 32 Bytes - nullreceiptsRoot
:DATA
, 32 Bytes - nullminer
:DATA
, 20 Bytes - nulldifficulty
:QUANTITY
- nulltotalDifficulty
:QUANTITY
- nullextraData
:DATA
- nullsize
:QUANTITY
- 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 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
- null
Sample Request
Sample Response
eth_getBlockByHash
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
See eth_getBlockByNumber
.
Sample Request
Sample Response
See eth_getBlockByNumber
.
eth_getTransactionByHash
eth_getTransactionByHash
Returns information about a transaction by block hash.
Parameters
DATA
, 32 Bytes - hash of a block.
Returns
Object
- A transaction object, or null
when no transaction was found:
hash
:DATA
- 32 Bytes, transaction hash.nonce
:QUANTITY
- the number of transactions made by the sender using Ontology EVM prior to this one.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.transactionIndex
:QUANTITY
- integer of the transactions index position in the block. null when its pending.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
- gas price provided by the sender in wei.gas
:QUANTITY
- gas provided by the sender.input
:DATA
- the data send along with the transaction.
Sample Request
Sample Response
eth_getTransactionByBlockHashAndIndex
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.
Sample Request
Returns
eth_getTransactionByBlockNumberAndIndex
eth_getTransactionByBlockNumberAndIndex
Returns information about a transaction by block number and transaction index position.
Parameters
QUANTITY|TAG
- integer of a block number, or the string"earliest"
,"latest"
or"pending"
.QUANTITY
- the transaction index position.
Returns
Sample Request
eth_getTransactionReceipt
eth_getTransactionReceipt
Returns the receipt of a transaction by transaction hash.
Note: The receipt is not available for pending transactions.
Parameters
DATA
, 32 Bytes - hash of a transaction.
Returns
Object
- A transaction receipt object, or null
when no receipt was found:
transactionHash
:DATA
, 32 Bytes - hash of the transaction.transactionIndex
:QUANTITY
- integer of the transactions index position in the block.blockHash
:DATA
, 32 Bytes - hash of the block where this transaction was in.blockNumber
:QUANTITY
- block number where this transaction was in.from
:DATA
, 20 Bytes - address of the sender.to
:DATA
, 20 Bytes - address of the receiver. null when its a contract creation transaction.cumulativeGasUsed
:QUANTITY
- The total amount of gas used when this transaction was executed in the block.gasUsed
:QUANTITY
- The amount of gas used by this specific transaction alone.contractAddress
:DATA
, 20 Bytes - The contract address created, if the transaction was a contract creation, otherwisenull
.logs
:Array
- Array of log objects, which this transaction generated.logsBloom
:DATA
, 256 Bytes - Bloom filter, nullstatus
:QUANTITY
, either1
(success) or0
(failure)
Sample Request
Sample Response
eth_pendingTransactions
eth_pendingTransactions
Access all pending transactions.
eth_pendingTransactionsByHash
eth_pendingTransactionsByHash
Access all pending transactions by transaction hash.
Last updated