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
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
wscat WS request
{"jsonrpc":"2.0","method":"admin_addPeer","params":["enode://f59c0ab603377b6ec88b89d5bb41b98fc385030ab1e4b03752db6f7dab364559d92c757c13116ae6408d2d33f0138e7812eb8b696b2a22fe3332c4b5127b22a3@127.0.0.1:30304"],"id":1}
JSON result
{
"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
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
wscat WS request
{"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}
JSON result
{
"jsonrpc": "2.0",
"id": 1,
"result": "Success"
}
The following example changes the debug level of all logs to WARN
.
curl HTTP request
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_changeLogLevel","params":["WARN"], "id":1}' http://127.0.0.1:8545
wscat WS request
{
"jsonrpc": "2.0",
"method": "admin_changeLogLevel",
"params": ["WARN"],
"id": 1
}
JSON result
{
"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
curl -X POST --data '{jsonrpc":"2.0","method":"admin_generateLogBloomCache", "params":["0x0", "0x10000"], "id":1}' http://127.0.0.1:8545
wscat WS request
{
"jsonrpc": "2.0",
"method": "admin_generateLogBloomCache",
"params": ["0x0", "0x10000"],
"id": 1
}
JSON result
{
"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 - integer representing a block number or one of the string tagslatest
,earliest
, orpending
, as described in block parameter -
toBlock
: string - integer representing a block number or one of the string tagslatest
,earliest
, orpending
, 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
curl -X POST --data '{"jsonrpc":"2.0","method":"admin_logsRemoveCache","params":["1", "100"], "id":1}' http://127.0.0.1:8545
wscat WS request
{
"jsonrpc": "2.0",
"method": "admin_logsRemoveCache",
"params": ["1", "100"],
"id": 1
}
JSON result
{
"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