Ethereum
The BCE API provides access to both the public Ethereum network and our own permission-based consortium network.
In order to access the Ethereum API endpoint
you must not only remember to include a valid method
but must also include a valid BCE API key
- http://bce.asia/api/cortex/v1/ethereum?method=blockNumber&key=your-api-key
- which should produce:
{
"code": "success",
"message": "Successfully fetched data",
"data": {
"status": 200,
"results": "0x74838a"
},
"_links": {
"up": [
{
"href": "http://bce.asia/api/cortex/v1"
}
],
"help": [
{
"name": "toc",
"href": "http://bce.asia/documentation/"
},
{
"name": "self",
"href": "http://bce.asia/documentation/ethereum"
}
],
"examples": [
{
"name": "simple",
"href": "http://bce.asia/api/cortex/v1/ethereum?method=blockNumber&key=your-api-key"
}
]
}
}
By default, Ethereum API requests assume you want to query the main public network. In order to communicate with the BCE network you should set the chain
parameter to bce
as follows:
http://bce.asia/api/cortex/v1/ethereum?method=blockNumber&key=your-api-key&chain=bce
Available Methods
blockNumber
- return the current block heightcall
- execute a message call without adding it to the blockchainestimateGas
- return an estmation for executing a particular transactiongasPrice
- returns the current gas price in weigetBalance
- returns the balance of an addressgetBlockByHash
- return a block based on its hashgetBlockByNumber
- return a block based on its heightgetBlockTransactionCountByHash
- returns the number of transactionsgetBlockTransactionCountByNumber
- returns the number of transactionsgetCode
- returns the compiled contract code at an addressgetLogs
- returns an array of logs based on a filter objectgetStorageAt
- returns the value from a storage position at an addressgetTransactionByBlockHashAndIndex
- returns a specific transactiongetTransactionByBlockNumberAndIndex
- returns a specific transactiongetTransactionByHash
- returns a specific transactiongetTransactionCount
- the number of transactions sent from an addresssendRawTransaction
- used to relay raw transactions to the network
Required options should be set via GET params
and piped if using URLs - for example - ?params=option_one|option_two
More information on each of the available methods
can be seen below:
blockNumber
( )
Although this function does not have any options, you can still use the chain
parameter to switch from public to private networks.
An example URL request:
http://bce.asia/api/cortex/v1/ethereum?method=blockNumber&key=your-api-key&chain=bce
call
( payload
, block
)
Both the payload
and block
are required.
The payload
should be a valid JSON transaction object - structured something like this:
{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
An example URL request:
estimateGas
( payload
)
The payload
is required and should be a valid JSON transaction object - structured something like this:
{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}
An example URL request:
gasPrice
( )
Although this function does not have any options, you can still use the chain
parameter to switch from public to private networks.
An example URL request:
http://bce.asia/api/cortex/v1/ethereum?method=gasPrice&key=your-api-key&chain=bce
getBalance
( address
, block
)
Both the address
and the block
are required.
The address
should be a string representation of an address (20 bytes) to check for balance.
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
An example URL request:
getBlockByHash
( hash
, showTxs
)
Both the hash
and the showTXs
are required.
The hash
should be a string representing the hash (32 bytes) of a block.
If set to true
the showTxs
will return full transactional objects, otherwise it will only return the transaction IDs.
An example URL request:
getBlockByNumber
( block
, showTxs
)
Both the block
and the showTXs
are required.
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
If set to true
the showTxs
will return full transactional objects, otherwise it will only return the transaction IDs.
An example URL request:
http://bce.asia/api/cortex/v1/ethereum?method=getBlockByNumber&key=your-api-key¶ms=0xF4240|false
getBlockTransactionCountByHash
( hash
)
The hash
is required and should be a string representing the hash (32 bytes) of a block.
An example URL request:
getBlockTransactionCountByNumber
( block
)
The required block
should be either a hex of an integer representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
An example URL request:
getCode
( address
, block
)
Both the address
and the block
required.
The address
should be a string representation of an address (20 bytes) to check for balance.
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
An example URL request:
getLogs
( payload
)
The payload
is required and must be a valid JSON filter object - structured something like this:
{
"address": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"fromBlock": "earliest",
"toBlock": "latest",
"topics": "0x241ea03ca20251805084d27d4440371c34a0b85ff108f6bb5611248f73818b80"
}
An example URL request:
getStorageAt
( address
, position
, block
)
The address
, position
and block
are all required.
The address
should be a string representation of an address (20 bytes) to check for balance.
The position
should be a hex code of the position in the storage.
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
An example URL request:
getTransactionByBlockHashAndIndex
( hash
, index
)
Both the hash
and the index
are required.
The hash
should be a string representing the hash (32 bytes) of a block.
The index
should be a hex of the integer representing the position in the block.
An example URL request:
getTransactionByBlockNumberAndIndex
( block
, index
)
Both the block
and theindex
are required.
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
The index
should be a hex of the integer representing the position in the block.
An example URL request:
getTransactionByHash
( hash
)
The hash
is required and should be a string representing the hash (32 bytes) of a transaction.
An example URL request:
getTransactionCount
( address
, block
)
Both the address
and the block
are required.
The block
should be either a hex of an integer (0x0) representing the block height or one of several reserved (string) key words.
Those keywords include "latest
", "earliest
" or "pending
".
An example URL request:
sendRawTransaction
( payload
)
The payload
is required and should be a valid JSON transaction object - structured something like this:
{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}
An example URL request: