I need to get the enode of my geth nodes before I start them up.. is there any way to do this via a command other than actually starting up the node ?
3 Answers
Using node hex in nodekey
file under .ethereum/geth/nodekey
and bootnode utility.
Assuming you are using Linux.
Check your nodekey hex :
$ cat ~/.ethereum/geth/nodekey
2ad3a9ccd99926514e77501c33c5fdbae6ecfdc6fc82853bc8f28772b13cd2df
Then with bootnode utility :
$ bootnode -nodekeyhex 2ad3a9ccd99926514e77501c33c5fdbae6ecfdc6fc82853bc8f28772b13cd2df -writeaddress
565f2cd2c5fd4f8798daaa65c858e4040d2b0db31b7d354177e126b34fea6163194c926a1cf3ffa1be29252518d6217a114479703e0f01ba5642a7d3bdc1137e
One of the binaries that can be generated by the go ethereum implementation is bootnode
that can be used (as the name suggests) to create a bootnode, i.e. a node that is involved only in the p2p management.
You can exploit this tool to generate a new id for the node:
bootnode -genkey <your-node-key-file>
Afterward you can use this file with geth:
geth --nodekey <your-node-key-file> -port $PORT
Obviously, to store the complete enode in a variable you need to have access to the IP and the port in bash:
PORT=<insert-the-port-of-the-node>
IP_ADDRESS=<insert-the-ip-of-the-machine>
NODEKEY=$(bootnode -nodekey <your-node-key-file> -writeaddress)
ENODE_ADDRESS="enode://$NODEKEY@$IP_ADDRESS:$PORT"
bootnode -nodekey ~/.ethereum/geth/nodekey -writeaddress
-
Welcome to the Ethereum Stack Exchange! Please check this ethereum.stackexchange.com/help/how-to-answer– eth ♦Jul 19, 2019 at 4:46