1

Using web3 to connect to a geth's node rpc API, is there a way to detect when a block has been mined by a specific node? The only way I've found so far is to redirect the node's console output to a file and parse that file. Is there a better way?

FYI - All the nodes are mining to the same public address so I can't use the miner property of a block.

2

One way to do it is to let each miner set their own 'extraData' field, as described in the documentation:

--extradata value         Block extra data set by the miner (default = client version)

This can be quickly shown by typing

web3.eth.getBlock('latest').extraData

on geth console.

Note: the output is in hexadecimal format, which can be converted into readable format with

web3.toAscii(web3.eth.getBlock('latest').extraData) 
| improve this answer | |
  • Yeah, I have discovered that option a few hours ago. I'll give it a try, but the miner I'm using is actually a fork of geth supporting a different blockchain implementation. I'm not sure they will honor this configuration. If not do you have any other idea? How does the miner knows when it mined a block successfully? I'd like to tap directly into that process if possible. Could I spy on the peers connection traffic to check if the miner tried to broadcast a block? – plalx Apr 17 '18 at 15:11
  • Hmm...detecting block broadcast is likely to be messy: what happens when a block is orphaned, or becomes an uncle? – Linmao Song Apr 17 '18 at 23:04
  • I confirmed that it works with the other blockchain, thanks. Also, any idea how to put a public address in there? I'm limited by the 32 chars limit. I've worked around the limit by converting to base64, but I'm sure there's a better way? – plalx Apr 18 '18 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.