-
Notifications
You must be signed in to change notification settings - Fork 20.2k
Go ethereum management API's
Beside the official DApp API interface the go ethereum node has support for additional management API's. These API's are offered using JSON-RPC and follow the same conventions as used in the DApp API. The go ethereum package comes with a console client which has support for all additional API's.
It is possible to specify the set of API's which are offered over an interface with the --${interface}api
command line argument for the go ethereum daemon. Where ${interface}
can be rpc
for the http
interface or ipc
for an unix socket on unix or named pipe on Windows.
For example, geth --ipcapi "admin,eth,miner" --rpcapi "eth,web3" --rpc
will
- enable the admin, official DApp and miner API over the IPC interface
- enable the eth and web3 API over the RPC interface
The HTTP RPC interface must be explicitly enabled using the --rpc
flag.
Please note that offering an API over the rpc
interface will give everyone access to the API who can access this interface (e.g. DApp's). So be careful which APIs you enable. By default geth enables all API's over the ipc
interface and only the db,eth,net and web3 APIs over the rpc
interface.
To determine which API's an interface provides the modules
transaction can be used, e.g. over an ipc
interface on unix systems:
echo '{"jsonrpc":"2.0","method":"modules","params":[],"id":1}' | nc -U $datadir/geth.ipc
will give all enabled modules including the version number:
{
"id":1,
"jsonrpc":"2.0",
"result":{
"admin":"1.0",
"db":"1.0",
"debug":"1.0",
"eth":"1.0",
"miner":"1.0",
"net":"1.0",
"personal":"1.0",
"shh":"1.0",
"txpool":"1.0",
"web3":"1.0"
}
}
These additional API's follow the same conventions as the official DApp API. Web3 can be extended and used to consume these additional API's.
The different functions are split into multiple smaller logically grouped API's. Examples are given for the Javascript console but can easily be converted to a rpc request.
2 examples:
-
Console:
miner.start()
-
IPC:
echo '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":1}' | nc -U $datadir/geth.ipc
-
RPC:
curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":74}' localhost:8545
With the number of THREADS as an arguments:
-
Console:
miner.start(4)
-
IPC:
echo '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":1}' | nc -U $datadir/geth.ipc
-
RPC:
curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":74}' localhost:8545
Provides various functions for managing a geth node
- addPeer
- [peers] (#admin_peers)
- importChain
- exportChain
- verbosity
- setSolc
- startRPC
- stopRPC
- startWS
- stopWS
This is the official DApp API. See for more information this page.
- dumpBlock
- [getBlockRlp] (#debug_getBlockRlp)
- printBlock
- processBlock
- seedHash
- setHead
This is the official DApp API. See for more information this page.
Allows full control over the miner and DAG.
Network related functions
Support for account management.
Gives insight in the transaction pool
This is the official DApp API. See for more information this page.
Add peer to node
-
Url
, peer enode url
boolean
indicating if the peer was added
admin.addPeer("enode://[email protected]:30303")
This property will show all connected peers.
admin.peers
Import an exported chain from file into node. This only works if no chain already exists: it does not delete any existing data.
-
Filename
, the fully qualified path to the file containing the chain to be imported
boolean
indicating if chain was imported
admin.importChain("/tmp/chain.txt")
Export the blockchain to a file
-
Filename
, the fully qualified path to the file where the blockchain must be exported
boolean
indicating if chain was exported
admin.exportChain("/tmp/chain.txt")
Set loglevel
-
Level
, the verbosity level with 0 the least and 6 the most verbose
boolean
indicating if chain was exported
admin.verbosity(5)
Set the path to the solidity compiler for eth.compileSolidity
.
-
Path
, full path to solidity compiler
string
in case the path was valid a brief description about the solidity compiler
admin.setSolc("/tmp/solc")
Start the HTTP RPC interface
(support for optional arguments requires geth version >=1.4)
-
ListenAddress
, open listener on this host (optional, default "localhost") -
ListenPort
, open listener on this port (optional, default 8545) -
CorsDomain
, the cross origin resource shared header (optional, default"") -
Apis
, comma separated list with the API modules which are offered over this interface (optional, default "eth,net,web3")
boolean
indication if the interface was started
admin.startRPC("127.0.0.1", 8545, "*", "eth,net,web3")
admin.startRPC(null, null, "http://chriseth.github.io", null)
Stop the HTTP RPC interface
boolean
indication if the interface was stopped
admin.stopRPC()
Start the websocket RPC interface (requires geth version >=1.4)
-
ListenAddress
, open listener on this host (optional, default "localhost") -
ListenPort
, open listener on this port (optional, default 8546) -
allowedDomains
, server side check on the Origin header (optional, default "") -
Apis
, comma separated list with the API modules which are offered over this interface (optional, default "eth,net,web3")
boolean
indication if the interface was started
admin.startWS("127.0.0.1", 8546, "*", "eth,net,web3")
admin.startWS(null, null, "http://chriseth.github.io", null)
Stop the websocket RPC interface
boolean
indication if the interface was stopped
admin.stopWS()
Dump block
integer
, block number
string
dumped block
debug.dumpBlock(0)
Get RLP encoded block
integer
, block number
string
RLP encoded block
debug.getBlockRlp(0)
Pretty print block
integer
, block number
string
formatted block
debug.printBlock(0)
Reprocess a block
integer
, block number
boolean
indication if the block was successful processed
debug.processBlock(0)
Block seed hash
NONE
string
block seed hash
debug.seedHash(eth.blockNumber)
Rewind the chain to a specific block
integer
, block number
boolean
indication if the new head was successful set
debug.setHead(eth.blockNumber-5000)
This will generates the DAG if necessary and starts the miner
integer
, an optional integer which specifies the number of threads, if not specified the number of CPU's is used
boolean
indicating if the miner was started
miner.start()
This will stop the miner
none
boolean
indicating if the miner was stopped
miner.stop()
Miner hashrate
none
integer
hashes p/s
miner.hashrate
Store additional data in a mined block
string
string with extra data (max 1024 bytes)
boolean
indication if the DATA was set
Set the gas price.
string
gas price, this can be a base8 (start with 0b), base10 (no prefix) or base16 representation (start with 0x)
boolean
indication if the new price was set
Pregenerate the DAG, this will allow for a seamless transition between the different epochs. If not enabled the miner will need to generate the DAG when a new epoch begins (each 30k blocks). This takes some time and will stop the miner until the DAG is generated.
none
boolean
indication if the command was successful
Stop DAG pregeneration.
none
boolean
indication if the command was successful
Start the DAG creator process.
none
boolean
indication if the command was successful
The number of connected peers
none
integer
number of peers
net.peerCount
Indication if this node is currently listening for new peers
none
boolean
indication if this node accepts new peers
net.listening
List all accounts
none
array
collection with accounts
personal.listAccounts
Create a new account
string
, passphrase to protect the account
string
address of the new account
personal.newAccount("mypasswd")
Unlock an account
string
, address of the account to delete
string
, passphrase of the account to delete (optional in console, user will be prompted)
integer
, unlock account for duration seconds, use 0 if the account must be locked forever. If not specified 300 is used by default.
boolean
indication if the account was unlocked
personal.unlockAccount(eth.coinbase, "mypasswd", 300)
Number of pending/queued transactions
NONE
pending
all processable transactions
queued
all non-processable transactions
txpool.status