Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Management API

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use the management API". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "how to use the management API"!

Enable Management API

To provide these management APIs via RPC access to an endpoint on Geth, you need to use the--${interface}api option when starting geth, where ${interface} can be rpc for an endpoint on HTTP, ws for an endpoint on a WebSocket, or ipc for an endpoint on a unix socket or windows named pipe.

For example, the following command enables unix sockets and access-side nodes over http:

~$ geth --ipcapi admin,eth,miner --rpcapi eth,web3 --rpc

End nodes on unix sockets provide the following APIs: admin, miner, and the official DApp API, eth.

End nodes on http provide the following APIs: web3, eth

RPC interfaces over HTTP must also be explicitly turned on with the--rpc flag.

It is important to note that providing APIs over HTTP (rpc) or WebSocket (ws) will allow everyone to access the APIs, so carefully review which API services you are providing. By default, Geth provides all APIs on the IPC side node and only db, eth, net, and web3 APIs on HTTP and WebSocket interfaces.

To see which APIs are available, you can use the modules call. For example, on unix systems, call via the ipc interface:

~$ echo '{"jsonrpc":"2.0","method":"rpc_modules","params":[],"id":1}' | nc -U $datadir/geth.ipc

The response will list all enabled API modules and their version numbers:

{ "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" }} Using the Management API

Geth provides management APIs that follow the same specifications as the official DApp APIs, so Web3 can be extended to support these additional APIs.

Different functions are grouped into logical groups. Examples on the JavaScript console are given below, but they can easily be converted to RPC requests.

For example, start mining at Geth terminal:

> miner.start()

Start mining via IPC endpoint:

~$ echo '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":1}' | nc -U $datadir/geth.ipc

Start mining via HTTP endpoint:

~$ curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":74}' localhost:8545

You can specify the number of mining threads by passing in a parameter when starting mining:

Geth terminal starts 4 threads mining:

> miner.start(4)

Start 4 threads mining via IPC node:

~$ echo '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":1}' | nc -U $datadir/geth.ipc

Start 4 threads mining via HTTP endpoint:

~$ curl -X POST --data '{"jsonrpc":"2.0","method":"miner_start","params":[4],"id":74}' localhost:8545Geth management API manifest

In addition to the official DApp API command spaces (eth, sh, web3), Geth provides the following additional administrative API namespaces:

admin: Geth Node Management

debug: Geth node debug

miner: Mining and directed acyclic graph (DAG) management

personal: account management

txpool: trading pool review

admin

The admin family API provides a set of non-standard RPC methods for tuning the operation of Geth instances, including but not limited to network node and RPC end node management.

The admin namespace includes the following RPC calls:

addPeer: Add a remote node

datadir: Get chain library data directory

nodeInfo: Get node information

peers: Get information about connected remote nodes

setSolc: Set solidity compiler path

startRPC: Start RPC services over HTTP

startWS: Start RPC service on WebSocket

stopRPC: Stop RPC services over HTTP

stopWS: Stop RPC services on WebSocket

debug

The debug family API provides a set of non-standard RPC methods that can be used to monitor and debug the operation of Geth, as well as to set certain debug flags at runtime.

backtraceAt: Set the tracking location

blockProfile: Enable time-limited block performance detection

cpuProfile: Enable CPU performance detection for limited time

dumpBlock: export block data

gcStats: Get garbage collection statistics

getBlockRlp: Get RPL encoded block data

goTrace: Enable time-limited go runtime trace

memStats: Get memory statistics

seedHash: Get block seed hash

setBlockProfileRate: Sets the block performance detection rate

setHead: Set local chain head block

stacks: Get the call stack

startCPUProfile: Enable CPU performance detection

startGoTrace: Enable goTrace

traceBlock: Get block opcode call stack

traceBlockByNumber: Get the specified serial number block opcode call stack

traceBlockByHash: Get the specified hash block opcode call stack

traceBlockFromFile: Get block file opcode call stack

traceTransaction

verbosity: Set log display level

vmodule: Set log visual mode

writeBlockProfile: Enable block performance detection

writeMemProfile: Enable memory performance testing

miner

The miner API allows you to remotely control node mining operations or set various parameters related to mining.

setExtra: Set additional data to be written to the mining block

setGasPrice: Sets the minimum price of gas that can be traded

start: Start mining

Stop: Stop mining

getHashRate: Gets the hash generation rate

setEtherbase: Set mining revenue account

personal

The API for the personal family manages private keys in the keystore.

importRawKey: import private key

listAccounts: List all accounts

lockAccount: Lock Account

newAccount: Create a new account

unlock Account: unlock account

sendTransaction: Send transaction

sign: signature

ecRecover: Extract the initiator address from the signature

txpool

The txpool family of APIs provides a set of non-standard RPC methods that can be used to view the contents of a transaction pool containing all pending and queued transactions.

content: Get details of trades in the pool

inspect: Get an overview of trades in the pool

status: Get trading pool status

At this point, I believe everyone has a deeper understanding of "how to use the management API". Let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report