--${interface}api
command line argument (where ${interface}
can be rpc
for the HTTP endpoint, ws
for the WebSocket endpoint and ipc
for the unix socket (Unix) or named pipe (Windows) endpoint).geth --ipcapi admin,eth,miner --rpcapi eth,web3 --rpc
--rpc
flag.rpc
) or WebSocket (ws
) interfaces will give everyone access to the APIs who can access this interface (DApps, browser tabs, etc). Be careful which APIs you enable. By default Geth enables all APIs over the IPC (ipc
) interface and only the db
, eth
, net
and web3
APIs over the HTTP and WebSocket interfaces.modules
JSON-RPC method can be invoked. For example over an ipc
interface on unix systems:miner.start()
echo '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":1}' | nc -U $datadir/geth.ipc
curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":74}' localhost:20635
miner.start(4)
echo '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":1}' | nc -U $datadir/geth.ipc
curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":74}' localhost:20635
eth
, shh
, web3
), Geth provides the following extra management API namespaces:admin
: Geth node managementdebug
: Geth node debuggingpersonal
: Account managementtxpool
: Transaction pool inspectionadmin
API gives you access to several non-standard RPC methods, which will allow you to have a fine grained control over your Geth instance, including but not limited to network peer and RPC endpoint management.addPeer
administrative method requests adding a new remote node to the list of tracked static nodes. The node will try to maintain connectivity to these nodes at all times, reconnecting every once in a while if the remote connection goes down.enode
URL of the remote peer to start tracking and returns a BOOL
indicating whether the peer was accepted for tracking or some error occurred.admin.AddPeer(url string) (bool, error)
admin.addPeer(url)
{"method": "admin_addPeer", "params": [url]}
datadir
administrative property can be queried for the absolute path the running Geth node currently uses to store all its databases.admin.Datadir() (string, error
)admin.datadir
{"method": "admin_datadir"}
peers
administrative property can be queried for all the information known about the connected remote nodes at the networking granularity. These include general information about the nodes themselves as participants of the ÐΞVp2p P2P overlay protocol, as well as specialized information added by each of the running application protocols (e.g. eth
, les
, shh
, bzz
).admin.Peers() ([]*p2p.PeerInfo, error
)admin.peers
{"method": "admin_peers"}
setSolc
administrative method sets the Solidity compiler path to be used by the node when invoking the eth_compileSolidity
RPC method. The Solidity compiler path defaults to /usr/bin/solc
if not set, so you only need to change it for using a non-standard compiler location.solc --version
.admin.SetSolc(path string) (string, error
)admin.setSolc(path)
{"method": "admin_setSolc", "params": [path]}
startRPC
administrative method starts an HTTP based JSON RPC API webserver to handle client requests. All the parameters are optional:host
: network interface to open the listener socket on (defaults to "localhost"
)port
: network port to open the listener socket on (defaults to 20635
)apis
: API modules to offer over this interface (defaults to "eth,net,web3"
)admin.StartRPC(host *string, port *rpc.HexNumber, cors *string, apis *string) (bool, error)
admin.startRPC(host, port, cors, apis)
{"method": "admin_startRPC", "params": [host, port, cors, apis]}
startWS
administrative method starts an WebSocket based JSON RPC API webserver to handle client requests. All the parameters are optional:host
: network interface to open the listener socket on (defaults to "localhost"
)port
: network port to open the listener socket on (defaults to 20635
)apis
: API modules to offer over this interface (defaults to "eth,net,web3"
)admin.StartWS(host *string, port *rpc.HexNumber, cors *string, apis *string) (bool, error)
admin.startWS(host, port, cors, apis)
{"method": "admin_startWS", "params": [host, port, cors, apis]}
stopRPC
administrative method closes the currently open HTTP RPC endpoint. As the node can only have a single HTTP endpoint running, this method takes no parameters, returning a boolean whether the endpoint was closed or not.admin.StopRPC() (bool, error
)admin.stopRPC()
{"method": "admin_stopRPC"
stopWS
administrative method closes the currently open WebSocket RPC endpoint. As the node can only have a single WebSocket endpoint running, this method takes no parameters, returning a boolean whether the endpoint was closed or not.admin.StopWS() (bool, error
)admin.stopWS()
{"method": "admin_stopWS"
debug
API gives you access to several non-standard RPC methods, which will allow you to inspect, debug and set certain debugging flags during runtime.<filename>:<line>
.debug.backtraceAt(string)
{"method": "debug_backtraceAt", "params": [string]}
debug_writeBlockProfile
.debug.blockProfile(file, seconds)
{"method": "debug_blockProfile", "params": [string, number]}
debug.cpuProfile(file, seconds)
{"method": "debug_cpuProfile", "params": [string, number]}
debug.DumpBlock(number uint64) (state.World, error)
debug.traceBlockByHash(number, [options])
{"method": "debug_dumpBlock", "params": [number]}
debug.gcStats()
{"method": "debug_gcStats", "params": []}
debug.GetBlockRlp(number uint64) (string, error)
debug.getBlockRlp(number, [options])
{"method": "debug_getBlockRlp", "params": [number]}
debug.goTrace(file, seconds)
{"method": "debug_goTrace", "params": [string, number]}
debug.memStats()
{"method": "debug_memStats", "params": []}
debug.SeedHash(number uint64) (string, error)
debug.seedHash(number, [options])
{"method": "debug_seedHash", "params": [number]}
debug.SetHead(number uint64)
debug.setHead(number)
{"method": "debug_setHead", "params": [number]}
debug_writeBlockProfile
.debug.setBlockProfileRate(rate)
{"method": "debug_setBlockProfileRate", "params": [number]}
debug.stacks()
{"method": "debug_stacks", "params": []}
debug.startCPUProfile(file)
{"method": "debug_startCPUProfile", "params": [string]}
debug.startGoTrace(file)
{"method": "debug_startGoTrace", "params": [string]}
debug.stopCPUProfile()
{"method": "debug_stopCPUProfile", "params": []}
debug.startGoTrace(file)
{"method": "debug_stopGoTrace", "params": []}
traceBlock
method will return a full stack trace of all invoked opcodes of all transaction that were included included in this block. Note: the parent of this block must be present or it will fail.debug.TraceBlock(blockRlp []byte, config. *vm.Config) BlockTraceResult
debug.traceBlock(tblockRlp, [options])
{"method": "debug_traceBlock", "params": [blockRlp, {}]}
traceBlockByNumber
accepts a block number and will replay the block that is already present in the database.debug.TraceBlockByNumber(number uint64, config. *vm.Config) BlockTraceResult
debug.traceBlockByNumber(number, [options])
{"method": "debug_traceBlockByNumber", "params": [number, {}]}
traceBlockByHash
accepts a block hash and will replay the block that is already present in the database.debug.TraceBlockByHash(hash common.Hash, config. *vm.Config) BlockTraceResult
debug.traceBlockByHash(hash, [options])
{"method": "debug_traceBlockByHash", "params": [hash {}]}
traceBlockFromFile
accepts a file containing the RLP of the block.debug.TraceBlockFromFile(fileName string, config. *vm.Config) BlockTraceResult
debug.traceBlockFromFile(fileName, [options])
{"method": "debug_traceBlockFromFile", "params": [fileName, {}]}
traceTransaction
debugging method will attempt to run the transaction in the exact same manner as it was executed on the network. It will replay any transaction that may have been executed prior to this one before it will finally attempt to execute the transaction that corresponds to the given hash.disableStorage
: BOOL
. Setting this to true will disable storage capture (default = false).disableMemory
: BOOL
. Setting this to true will disable memory capture (default = false).disableStack
: BOOL
. Setting this to true will disable stack capture (default = false).tracer
: STRING
. Setting this will enable JavaScript-based transaction tracing, described below. If set, the previous four arguments will be ignored.timeout
: STRING
. Overrides the default timeout of 5 seconds for JavaScript-based tracing calls. Valid values are described here.debug.TraceTransaction(txHash common.Hash, logger *vm.LogConfig) (*ExecutionResurt, error)
debug.traceTransaction(txHash, [options])
{"method": "debug_traceTransaction", "params": [txHash, {}]}
tracer
option in the second argument enables JavaScript-based tracing. In this mode, tracer
is interpreted as a JavaScript expression that is expected to evaluate to an object with (at least) two methods, named step
and result
.step
is a function that takes two arguments, log and db, and is called for each step of the EVM, or when an error occurs, as the specified transaction is traced.log
has the following fields:pc
: Number, the current program counterop
: Object, an OpCode object representing the current opcodegas
: Number, the amount of gas remaininggasPrice
: Number, the cost in wei of each unit of gasmemory
: Object, a structure representing the contract's memory spacestack
: array[big.Int], the EVM execution stackdepth
: The execution depthaccount
: The address of the account executing the current operationerr
: If an error occured, information about the errorerr
is non-null, all other fields should be ignored.log
object is reused on each execution step, updated with current values; make sure to copy values you want to preserve beyond the current call. For instance, this step function will not work:log.op
has the following methods:isPush()
- returns true iff the opcode is a PUSHntoString()
- returns the string representation of the opcodetoNumber()
- returns the opcode's numberlog.memory
has the following methods:slice(start, stop)
- returns the specified segment of memory as a byte slicelength()
- returns the length of the memorylog.stack
has the following methods:peek(idx)
- returns the idx-th element from the top of the stack (0 is the topmost element) as a big.Intlength()
- returns the number of elements in the stackdb
has the following methods:getBalance(address)
- returns a big.Int
with the specified account's balancegetNonce(address)
- returns a Number with the specified account's noncegetCode(address)
- returns a byte slice with the code for the specified accountgetState(address, hash)
- returns the state value for the specified account and the specified hashexists(address)
- returns true if the specified address exists.String()
on them. For convenience, big.NewInt(x)
is provided, and will convert a uint to a Go BigInt.debug_vmodule
.debug.verbosity(level)
{"method": "debug_vmodule", "params": [number]}
debug.vmodule(string)
{"method": "debug_vmodule", "params": [string]}
debug.writeBlockProfile(file)
{"method": "debug_writeBlockProfile", "params": [string]}
--memprofilerate
flag.debug.writeMemProfile(file string)
{"method": "debug_writeBlockProfile", "params": [string]}
miner
API allows you to remote control the node's mining operation and set various mining specific settings.miner.setExtra(extra string) (bool, error)
miner.setExtra(string)
{"method": "miner_setExtra", "params": [string]}
miner.setGasPrice(number *rpc.HexNumber) bool
miner.setGasPrice(number)
{"method": "miner_setGasPrice", "params": [number]}
miner.Start(threads *rpc.HexNumber) (bool, error)
miner.start(number)
{"method": "miner_start", "params": [number]}
miner.Stop() bool
miner.stop()
{"method": "miner_stop", "params": []}
miner.SetEtherbase(common.Address) bool
miner.setEtherbase(address)
{"method": "miner_setEtherbase", "params": [address]}
personal.importRawKey(keydata, passphrase)
{"method": "personal_importRawKey", "params": [string, string]}
personal.listAccounts
{"method": "personal_listAccounts", "params": []}
personal.lockAccount(address)
{"method": "personal_lockAccount", "params": [string]}
newAccount
will prompt for a passphrase when it is not supplied as the argument.personal.newAccount()
{"method": "personal_newAccount", "params": [string]}
eth_sign
and eth_sendTransaction
while it is unlocked.personal.unlockAccount(address, passphrase, duration)
{"method": "personal_unlockAccount", "params": [string, string, number]}
null
as the passphrase.eth_sendTransaction
and contains the from
address. If the passphrase can be used to decrypt the private key belogging to tx.from
the transaction is verified, signed and send onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.personal.sendTransaction(tx, passphrase)
{"method": "personal_sendTransaction", "params": [tx, string]}
personal_signAndSendTransaction
as that was the original introductory name and only later renamed to the current final version.sign(keccack256("\x19Ethereum Signed Message:\n" + len(message) + message)))
.personal.sign(message, account, [password])
{"method": "personal_sign", "params": [message, account, password]}
ecRecover
returns the address associated with the private key that was used to calculate the signature in personal_sign
.