0

I've lunched an Ethereum server based on Geth. Now, I need to be notified about all incoming transactions on my generated accounts.
In my previous Bitcoin Core server, I had an option in its config file like this:

walletnotify=php -f /path/notify.php %s

Through this code, Bitcoin server sends all events to the specified file, and then, I process other things.
But I don't know what is the exact mechanism to do that in Geth and Ethereum. The official documents, only said use --wsaddr, --wsport, --wsapi flags. But, where do I have to listen to notifications?

0

Websockets

I'd recommend this page for an overview of the different flags you can use with Geth on launch. It mentions there that the default address for the websocket (if turned on with --ws) is localhost:8546.

Logging all transactions

I don't think this will output all new txs out-of-the-box, though I am a bit out of my water here. You could use a JavaScript script to accomplish this without websockets or ipc (loading a script with the --js flag followed by the path to the script), or you could use subscriptions. The way your question is phrased implies your looking for the latter, so I'll try to focus on that. The page in the docs is the one right after the one you linked: https://geth.ethereum.org/docs/rpc/pubsub .

You're going to need to make a call to the exposed websocket (or rpc, if you prefer - I'm sticking with websockets since you mentioned them in the question). You could use Postman for this if you like. (If someone has a cleaner way of doing this, please suggest it.) In order to subscribe to receive new blocks as they're added to the chain, and then to include all txs in the block, send:

{"id": 1, "method": "eth_subscribe", "params": ["newHeads", {"includeTransactions": true}]}

If you're using the default websocket settings, for instance, that object should be sent to localhost:8546.

You should receive an object of data in return, something like:

{"jsonrpc":"2.0","id":1,"result":"0xcd0c3e8af590364c09d0fa6a1210faf5"}

The result is your subscription id. You should now get a stream of data over websockets. Take note of your subscription id, you'll need it if you want to unsubscribe.

| improve this answer | |
  • Thank you. It seems the localhost:8546 would be my need. I have to check it out... – Mohammad Saberi Mar 25 at 15:37
  • If this answered your question, it would be a big help if you accepted the answer. (That's the checkmark under the arrows for voting on the question.) Glad I could help! – The Renaissance Mar 25 at 17:07
0

If you are using web3js, look at web3.eth.subscribe function. It implements asynchronous notifications about various blockchain events, such as new blocks or event logs. Under the hood it just polls the node periodically, as geth doesn't support push notifications. For token transfers you need to subscribe to transfer event. For ether transfer things are a bit more complicated, as there is no simple way to iterate through all the ether transfers within a block. Here is nice undocumented feature, that could help monitoring balances of large sets of addresses effectively: https://github.com/ethereum/go-ethereum/pull/15512

Let me know, if you need more details.

| improve this answer | |

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.