Besu API methods
- This reference contains API methods that apply to both public and private networks. For private-network-specific API methods, see the private network API reference.
- All JSON-RPC HTTP examples use the default host and port endpoint
http://127.0.0.1:8545
. If using the --rpc-http-host or --rpc-http-port options, update the endpoint. - Most example requests are made against private networks. Depending on network configuration and activity, your example results might be different.
View the Besu JSON-RPC APIs documentation in the Postman format and obtain example requests in multiple coding languages.
Run in Postman
Click the following button to fork the collection and run requests directly on your local network.
Download collection
Alternatively you can download the JSON collection file.
ADMIN
methods
The ADMIN
API methods provide administrative functionality to manage your node.
The ADMIN
API methods are not enabled by default for JSON-RPC. To enable the ADMIN
API methods, use the --rpc-http-api
or --rpc-ws-api
options.
admin_addPeer
Adds a static node.
If connections are timing out, ensure the node ID in the enode URL is correct.
Parameters
enode
: string - enode URL of peer to add
Returns
result
: boolean - true
if peer added or false
if peer already a static node
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_addPeer","params":["enode://f59c0ab603377b6ec88b89d5bb41b98fc385030ab1e4b03752db6f7dab364559d92c757c13116ae6408d2d33f0138e7812eb8b696b2a22fe3332c4b5127b22a3@127.0.0.1:30304"],"id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0","method":"admin_addPeer","params":["enode://f59c0ab603377b6ec88b89d5bb41b98fc385030ab1e4b03752db6f7dab364559d92c757c13116ae6408d2d33f0138e7812eb8b696b2a22fe3332c4b5127b22a3@127.0.0.1:30304"],"id":1}
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
admin_changeLogLevel
Changes the log level without restarting Besu. You can change the log level for all logs, or you can change the log level for specific packages or classes.
You can specify only one log level per RPC call.
Parameters
-
level
: string - log level -
log_filter
: array - (optional) packages or classes for which to change the log level
Returns
result
: string - Success
if the log level has changed, otherwise error
The following example changes the debug level for specified classes to DEBUG
.
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0", "method":"admin_changeLogLevel", "params":["DEBUG", ["org.hyperledger.besu.ethereum.eth.manager","org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.ApiHandler"]], "id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0", "method":"admin_changeLogLevel", "params":["DEBUG", ["org.hyperledger.besu.ethereum.eth.manager","org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.ApiHandler"]], "id":1}
{
"jsonrpc": "2.0",
"id": 1,
"result": "Success"
}
The following example changes the debug level of all logs to WARN
.
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_changeLogLevel","params":["WARN"], "id":1}' http://127.0.0.1:8545
{
"jsonrpc": "2.0",
"method": "admin_changeLogLevel",
"params": ["WARN"],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": "Success"
}
admin_generateLogBloomCache
Generates cached log bloom indexes for blocks. APIs such as eth_getLogs
and eth_getFilterLogs
use the cache for improved performance.
Manually executing admin_generateLogBloomCache
is not required unless the --auto-log-bloom-caching-enabled
command line option is set to false.
Each index file contains 100000 blocks. The last fragment of blocks less than 100000 are not indexed.
Parameters
-
startBlock
: string - block to start generating indexes -
endBlock
: string - block to stop generating indexes
Returns
result
: object - log bloom index details:
-
startBlock
: string - starting block for the last requested cache generation -
endBlock
: string - ending block for the last requested cache generation -
currentBlock
: string - most recent block added to the cache -
indexing
: boolean - indicates if indexing is in progress -
boolean - indicates acceptance of the request from this call to generate the cache
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{jsonrpc":"2.0","method":"admin_generateLogBloomCache", "params":["0x0", "0x10000"], "id":1}' http://127.0.0.1:8545
{
"jsonrpc": "2.0",
"method": "admin_generateLogBloomCache",
"params": ["0x0", "0x10000"],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"startBlock": "0x0",
"endBlock": "0x10000",
"currentBlock": "0x0",
"indexing": true,
"requestAccepted": true
}
}
admin_logsRemoveCache
Removes cache files for the specified range of blocks.
Parameters
-
fromBlock
: string - hexadecimal or decimal integer representing a block number or one of the string tagslatest
,earliest
,pending
,finalized
, orsafe
, as described in block parameter -
toBlock
: string - hexadecimal or decimal integer representing a block number or one of the string tagslatest
,earliest
,pending
,finalized
, orsafe
, as described in block parameter
You can skip a parameter by using an empty string, ""
. If you specify:
-
No parameters, the call removes cache files for all blocks.
-
Only
fromBlock
, the call removes cache files for the specified block. -
Only
toBlock
, the call removes cache files from the genesis block to the specified block.
Returns
result
: object - Cache Removed
status or error
.
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_logsRemoveCache","params":["1", "100"], "id":1}' http://127.0.0.1:8545
{
"jsonrpc": "2.0",
"method": "admin_logsRemoveCache",
"params": ["1", "100"],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"Status": "Cache Removed"
}
}
admin_logsRepairCache
Repairs cached logs by fixing all segments starting with the specified block number.
Parameters
startBlock
: string - decimal index of the starting block to fix; defaults to the head block
Returns
result
: object - status of the repair request; Started
or Already running
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_logsRepairCache","params":["1200"], "id":1}' http://127.0.0.1:8545
{
"jsonrpc": "2.0",
"method": "admin_logsRepairCache",
"params": ["1200"],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"Status": "Started"
}
}
admin_nodeInfo
Returns networking information about the node. The information includes general information about the node and specific information from each running Ethereum sub-protocol (for example, eth
).
Parameters
None
Returns
result
: object - node object with the following fields:
-
enode
: string - enode URL of the node -
listenAddr
: string - host and port for the node -
name
: string - client name -
id
: string - node public key -
ports
: object - peer discovery and listening ports -
protocols
: object - list of objects containing information for each Ethereum sub-protocol
If the node is running locally, the host of the enode
and listenAddr
display as [::]
in the result. When advertising externally, the external address displayed for the enode
and listenAddr
is defined by --nat-method
.
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"enode": "enode://87ec35d558352cc55cd1bf6a472557797f91287b78fe5e86760219124563450ad1bb807e4cc61e86c574189a851733227155551a14b9d0e1f62c5e11332a18a3@[::]:30303",
"listenAddr": "[::]:30303",
"name": "besu/v1.0.1-dev-0d2294a5/osx-x86_64/oracle-java-1.8",
"id": "87ec35d558352cc55cd1bf6a472557797f91287b78fe5e86760219124563450ad1bb807e4cc61e86c574189a851733227155551a14b9d0e1f62c5e11332a18a3",
"ports": {
"discovery": 30303,
"listener": 30303
},
"protocols": {
"eth": {
"config": {
"chainId": 2018,
"homesteadBlock": 0,
"daoForkBlock": 0,
"daoForkSupport": true,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"constantinopleFixBlock": 0,
"ethash": {
"fixeddifficulty": 100
}
},
"difficulty": 78536,
"genesis": "0x43ee12d45470e57c86a0dfe008a5b847af9e372d05e8ba8f01434526eb2bea0f",
"head": "0xc6677651f16d07ae59cab3a5e1f0b814ed2ec27c00a93297b2aa2e29707844d9",
"network": 2018
}
}
}
}
admin_peers
Returns networking information about connected remote nodes.
Parameters
None
Returns
result
: array of objects - list of objects returned for each remote node, with the following fields.
-
version
: string - P2P protocol version -
name
: string - client name -
caps
: array of strings - list of Ethereum sub-protocol capabilities -
network
: object - local and remote addresses established at time of bonding with the peer (the remote address might not match the hex value forport
; it depends on which node initiated the connection.) -
port
: string - port on the remote node on which P2P discovery is listening -
id
: string - node public key (excluding the0x
prefix, the node public key is the ID in the enode URLenode://<id ex 0x>@<host>:<port>
.) -
protocols
: object - current state of peer includingdifficulty
andhead
(head
is the hash of the highest known block for the peer.) -
enode
: string - enode URL of the remote node
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_peers","params":[],"id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0","method":"admin_peers","params":[],"id":1}
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"version": "0x5",
"name": "besu/v20.10.4-dev-0905d1b2/osx-x86_64/adoptopenjdk-java-11",
"caps": ["eth/62", "eth/63", "eth/64", "eth/65", "IBF/1"],
"network": {
"localAddress": "192.168.1.229:50115",
"remoteAddress": "168.61.153.255:40303"
},
"port": "0x765f",
"id": "0xe143eadaf670d49afa3327cae2e655b083f5a89dac037c9af065914a9f8e6bceebcfe7ae2258bd22a9cd18b6a6de07b9790e71de49b78afa456e401bd2fb22fc",
"protocols": {
"eth": {
"difficulty": "0x1ac",
"head": "0x964090ae9277aef43f47f1b8c28411f162243d523118605f0b1231dbfdf3611a",
"version": 65
}
},
"enode": "enode://e143eadaf670d49afa3327cae2e655b083f5a89dac037c9af065914a9f8e6bceebcfe7ae2258bd22a9cd18b6a6de07b9790e71de49b78afa456e401bd2fb22fc@127.0.0.1:30303"
}
]
}
admin_removePeer
Removes a static node.
Parameters
enode
: string - enode URL of peer to remove
Returns
result
: boolean - true
if peer removed or false
if peer not a static node
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_removePeer","params":["enode://f59c0ab603377b6ec88b89d5bb41b98fc385030ab1e4b03752db6f7dab364559d92c757c13116ae6408d2d33f0138e7812eb8b696b2a22fe3332c4b5127b22a3@127.0.0.1:30304"],"id":1}' http://127.0.0.1:8545
{"jsonrpc":"2.0","method":"admin_removePeer","params":["enode://f59c0ab603377b6ec88b89d5bb41b98fc385030ab1e4b03752db6f7dab364559d92c757c13116ae6408d2d33f0138e7812eb8b696b2a22fe3332c4b5127b22a3@127.0.0.1:30304"],"id":1}
{
"jsonrpc": "2.0",
"id": 1,
"result": true
}
DEBUG
methods
The DEBUG
API methods allow you to inspect and debug the network. The DEBUG
API is a more verbose alternative to the TRACE
API, and its main purpose is compatibility with tools such as Remix. Where these APIs overlap, we recommend using the TRACE
API for production use over the DEBUG
API. Specifically, we recommend trace_block
over debug_traceBlock
, and trace_transaction
over debug_traceTransaction
.
The DEBUG
API methods are not enabled by default for JSON-RPC. To enable the DEBUG
API methods, use the --rpc-http-api
or --rpc-ws-api
options.
debug_accountAt
Returns account information at the specified index of the specified block.
Parameters
-
blockHashOrNumber
: string - block hash or number at which to retrieve account information -
txIndex
: number - transaction index at which to retrieve account information -
address
: string - contract or account address for which to retrieve information
Returns
result
: object - account details object with the following fields:
-
code
: data - code for the account. Displays0x0
if the address is an externally owned account. -
nonce
: quantity - number of transactions made by the account before this one -
balance
: quantity - balance of the account in Wei -
codehash
: data - code hash for the account
This example uses an externally owned account address for the address
parameter.
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"debug_accountAt","params":["0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6", 0, "0xbcde5374fce5edbc8e2a8697c15331677e6ebf0b"],"id":1}' http://127.0.0.1:8545
{
"jsonrpc": "2.0",
"method": "debug_accountAt",
"params": [
"0xc8df1f061abb4d0c107b2b1a794ade8780b3120e681f723fe55a7be586d95ba6",
0,
"0xbcde5374fce5edbc8e2a8697c15331677e6ebf0b"
],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"code": "0x0",
"nonce": "0x5",
"balance": "0xad78ebc5ac6200000",
"codehash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
}
}
This example uses a contract address for the address
parameter.
- curl HTTP request
- wscat WS request
- JSON result
curl -X POST --data '{"jsonrpc":"2.0","method":"debug_accountAt","params":["0x2b76b3a2fc44c0e21ea183d06c846353279a7acf12abcc6fb9d5e8fb14ae2f8c", 0, "0x0e0d2c8f7794e82164f11798276a188147fbd415"],"id":1}' http://127.0.0.1:8545
{
"jsonrpc": "2.0",
"method": "debug_accountAt",
"params": [
"0x2b76b3a2fc44c0e21ea183d06c846353279a7acf12abcc6fb9d5e8fb14ae2f8c",
0,
"0x0e0d2c8f7794e82164f11798276a188147fbd415"
],
"id": 1
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"code": "0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063b27b880414610030575b600080fd5b61004a60048036038101906100459190610108565b61004c565b005b60606000806000604051935036600085376000803686885af490503d9150816000853e806000811461007d57610093565b60008311156100925761012085019350836040525b5b5060008114156100ec578473ffffffffffffffffffffffffffffffffffffffff167f410d96db3f80b0f89b36888c4d8a94004268f8d42309ac39b7bcba706293e099856040516100e3919061016e565b60405180910390a25b5050505050565b60008135905061010281610227565b92915050565b60006020828403121561011e5761011d610211565b5b600061012c848285016100f3565b91505092915050565b600061014082610190565b61014a818561019b565b935061015a8185602086016101de565b61016381610216565b840191505092915050565b600060208201905081810360008301526101888184610135565b905092915050565b600081519050919050565b600082825260208201905092915050565b60006101b7826101be565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60005b838110156101fc5780820151818401526020810190506101e1565b8381111561020b576000848401525b50505050565b600080fd5b6000601f19601f8301169050919050565b610230816101ac565b811461023b57600080fd5b5056fea2646970667358221220fdfb5c371055342507b8fb9ca7b0c234f79819bd5cb05c0d467fb605de979eb564736f6c63430008060033",
"nonce": "0x1",
"balance": "0x0",
"codehash": "0xf5f334d41776ed2828fc910d488a05c57fe7c2352aab2d16e30539d7726e1562"
}
}
debug_accountRange
Retesteth uses debug_accountRange
to implement debugging.
Returns the accounts for a specified block.