How can I use Geth (or any other client) to get a list of my peer nodes on the Ethereum network. I see there's a function to get the number of nodes using the web3 api, but I need a list of node IDs or IPs.
[Ethereum] Get a peer list for the geth node
go-ethereumnodesweb3js
Related Solutions
Q: I know that when a new geth instance runs it connects to the bootstrap nodes. What I want to know that do other nodes download blockchain from the bootstrap nodes or nor?
A: No. Regular nodes do not download the blockchain from bootnodes. The only role for the bootnodes is to allow regular nodes to connect to and get the connection information on other regular nodes. The regular nodes will then use this information to connect to other regular nodes.
Q: Bootstrap nodes are highly available so why just simply connect to bootstrap nodes instead of connecting to some other node in the network.
A: The bootnode's only role is to provide the connection information for regular nodes to connect to each other. The connection information for several bootnodes are hard-coded into the regular node source code - see bootnodes.go
As the bootnodes only serve very little information to each regular node, the bootnode server resources can be focussed on providing this information and not get bogged down transferring the blockchain data.
Q What if bootstrap nodes provide wrong information. The whole network is compromised right?
A Not necessarily. You are able to specify new bootnodes on the command line parameters of the regular node client:
geth help | grep bootnode
--bootnodes value Comma separated enode URLs for P2P discovery bootstrap
You are also able to manually enter a list of other regular nodes on the network using the admin.addPeer(...)
command.
Recently many users reported that their regular nodes was not able to find peers. There were some problems with the bootnodes. See geth does not sync out of the box.
The temporary workaround was to get a list of regular node connection information from peers that were already connected to peers, and pasting this connection information into the regular node that was experiencing the peer discovery problem. See How can I create a list of peers from my syncing geth node to manually paste into my non-syncing geth node using the admin.addPeer() command?.
Q: How is a regular node different than a bootstrap node?
A The regular node has the peer discovery mechanism of the bootstrap node. Additionally, the regular node will download and synchronise the blockchain with other regular nodes. The bootstrap node cannot be used directly to synchronise the blockchain.
Q: And also How does peer discovery actually works?
A: See Node discovery protocol and What are the peer discovery mechanisms involved in Ethereum?
Q: What if nodes only download and not upload?
A: There are sufficient nodes (~6,000) on the network that your node should find other nodes to download from.
Q: What if I execute a denial of service attack which connect to many nodes in the network and downloads blockchain?
A: You will need a lot of computing and networking resources to try to execute a denial of service attack on ~6,000 nodes.
To get the pending transactions you need a node that you're running on your own because this type of action requires a lot of resources.
You can run your own Geth node and wait until it is synchronized. When I want to run a Geth node on the main net and query for the transaction pool, I usually start it like this.
Download the Geth binary and rename it as geth.bin
.
Then run:
./geth.bin --datadir=./chaindata \
--rpc --rpcapi="eth,net,rpc,web3,txpool,personal,debug,account" \
--rpccorsdomain='*' --port 30303 \
--txpool.globalslots=250000 \
--txpool.globalqueue=50000 \
console
The important parts are:
--rpc
enables rpc requests, so you can connect with web3.js / web3py / ...--rpcapi
defines what APIs are available over RPC; the important one in this case istxpool
which enables a Geth specific API to query for the transaction pool; this is usually faster than the standard one. Documented here as a non-standard RPC method;--txpool.globalslots
and--txpool.globalqueue
increases the number of slots available for the pending transactions; otherwise it will ignore other pending transactions once it reaches a specific number (by default 4096)console
it will open a console where you can run commands in.
After you start Geth like that and wait for it to be synchronized, you can run commands inside the open console.
txpool.status
doc will display a statistic of pending and queued transactions. Pending are the ones that you care about, might be included in the next blocks if the miners choose to add them.
> txpool.status
{
pending: 1234,
queued: 4321
}
txpool.content
doc will display details about each transaction in the current lists.
> txpool.content
{
pending: {
0x0216d5032f356960cd3749c31ab34eeff21b3395: {
806: {
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0x0216d5032f356960cd3749c31ab34eeff21b3395",
gas: "0x5208",
gasPrice: "0xba43b7400",
hash: "0xaf953a2d01f55cfe080c0c94150a60105e8ac3d51153058a1f03dd239dd08586",
input: "0x",
nonce: "0x326",
to: "0x7f69a91a3cf4be60020fb58b893b7cbb65376db8",
transactionIndex: null,
value: "0x19a99f0cf456000"
}
}
},
queued: {
0x976a3fc5d6f7d259ebfb4cc2ae75115475e9867c: {
3: {
blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
blockNumber: null,
from: "0x976a3fc5d6f7d259ebfb4cc2ae75115475e9867c",
gas: "0x15f90",
gasPrice: "0x4a817c800",
hash: "0x57b30c59fc39a50e1cba90e3099286dfa5aaf60294a629240b5bbec6e2e66576",
input: "0x",
nonce: "0x3",
to: "0x346fb27de7e7370008f5da379f74dd49f5f2f80f",
transactionIndex: null,
value: "0x1f161421c8e0000"
}
}
}
}
Best Answer
Use
admin.peers
to get a list of the currently connected peers:This
admin.peers
property and other management APIs are documented on the go-ethereum wiki.