I am trying to get latest blocks data and gets all the transaction IDS inside the block and send that transaction IDS array to an api server. I am using this command in geth console :

 eth.filter('latest').watch(function(err, result){console.log(result)})

Is there a way in which a script will run 24/7 in geth console(get attach) and run the above command to get latest block data and send the transaction IDS array to an api server? Any ideas/help is greatly appreciated, Thanks!

2 Answers 2


Use --exec along with geth attach:

geth --exec "<code>" attach <target>

For more information and examples, including the execution of files (loading them from the specified code), see Non-interactive use: JSRE script mode.


You can directly run the JavaScript script under node VM. It will have the same execution context as geth attach that is effectively a JavaScript console

Examples (scroll to end):



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.