14

I'm setting a private blockchain using parity rust client.

In gethI can use admin.nodeInfo and get enode from there. But how can I get enode in parity client?

Igor Barinov
  • 2,138
  • 1
  • 16
  • 25

4 Answers4

10

Another way to get enode information is to send a POST request with the header Content-Type: application/json to the RPC port of the node with the following body:

{ "method": "parity_enode", "params": [], "id": 1, "jsonrpc": "2.0" }

Official documentation: https://wiki.parity.io/JSONRPC-parity-module.html#parity_enode

Ajoy Bhatia
  • 1,446
  • 15
  • 31
  • 2
    here is a handy snippet: curl -H "Content-Type: application/json" -k --data '{ "method": "parity_enode", "params": [], "id": 1, "jsonrpc": "2.0" }' -X POST http://localhost:8545 – Igor Barinov Jan 12 '20 at 16:54
4

Parity doesn't include a Javascript interpreter. However, as per the documentation, if you first install node/NPM then you'll be able to install and use the existing Ethereum Web3 API.

$ npm install web3

$ node
> Web3 = require("web3")
> web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
> web3.eth.blockNumber
743397
Richard Horrocks
  • 37,835
  • 13
  • 87
  • 144
3

parity's enode info is written to the console when you start the program.

user@Kumquat:~$ parity 
2016-08-26 00:57:35 Starting Parity/v1.2.2-beta/x86_64-linux-gnu/rustc1.10.0
2016-08-26 00:57:35 Using a conversion rate of Ξ1 = US$11.22 (21220608000 wei/gas)
2016-08-26 00:57:35 Configured for Frontier/Homestead using Ethash engine
2016-08-26 00:57:36 Public node URL: enode://031b1e872cea345c5b6b2ff9dfc16213021071bb320987fdf9881f4500880e57a5a8d6b8b57aaf0de263df0a88d757f978039e09fa9758c4d814850c4172ddf7@0.0.0.0:30303
...

Your enode info is enode://031b1e872cea345c5b6b2ff9dfc16213021071bb320987fdf9881f4500880e57a5a8d6b8b57aaf0de263df0a88d757f978039e09fa9758c4d814850c4172ddf7@0.0.0.0:30303.

0.0.0.0 is your localhost. Replace it with your computer's IP address if you want to connect to the parity node from other computers.

BokkyPooBah
  • 40,274
  • 14
  • 123
  • 193
  • 1
    Thank you, I've found that. I'd like to automate the process for private Blockchain , e.g. to make a query to parity, save enode to index.html, serve it from local web server , and other nodes will curl this URL to construct their bootstrap setting – Igor Barinov Aug 25 '16 at 15:03
  • the only way is to parse the log? .. or to modify parity source code with a new JSON RPC method to get nodeid? – Igor Barinov Aug 25 '16 at 15:43
  • 1
    I just scanned through the source code and could not find any admin API - see https://github.com/ethcore/parity/blob/master/parity/rpc_apis.rs#L51-L60 . So your logs may be the only way. – BokkyPooBah Aug 25 '16 at 15:55
  • 1
    I searched and tested the JSONRPC API documented at https://github.com/ethcore/parity/wiki/JSONRPC-ethcore-module but no nodeInfo available. – BokkyPooBah Aug 25 '16 at 16:06
  • @IgorBarinov - there is a JSON RPC method parity_enode to get enode info. See my answer dated Feb 10, 2017 below. – Ajoy Bhatia Feb 22 '17 at 19:51
2

Finally I wrote a workaround with a bash script. I run it on a node using foreman and it writes nodeId to a static web server. Other nodes use curl to get nodeId for bootstrapping.

touch /var/log/parity.log
tail -f /var/log/parity.log | while read LOGLINE
do
   [[ "${LOGLINE}" == *"enode"* ]] && echo $LOGLINE | grep -oEi '(enode.*@)' > /var/www/index.html
done
David Mihal
  • 397
  • 1
  • 3
  • 10
Igor Barinov
  • 2,138
  • 1
  • 16
  • 25