I have made a contract which generates a public event on blockchain that will notify client about a transaction. To listen to the event I have written following snippet in geth console:

var event = token.CoinTransfer({}, '', function(error, result){
  if (!error)
    console.log("Coin transfer: " + result.args.amount + " tokens were sent. Balances now are as following: \n Sender:\t" + result.args.sender + " \t" + token.coinBalanceOf.call(result.args.sender) + " tokens \n Receiver:\t" + result.args.receiver + " \t" + token.coinBalanceOf.call(result.args.receiver) + " tokens" )

Now instead of console.log() I want these transaction to be stored in a text file TransactionHistory.txt. How can we do this? Is there a better way than listening to event, to maintain transaction logs?

2 Answers 2


Probably is best that you exec the script from a file anyway

 geth --exec 'loadScript("/tmp/test.js")' attach 

Then you can direct the output, for example in Linux and Mac:

 geth --exec 'loadScript("/tmp/checkbalances.js")' attach > log.txt
  • It would be better if there is a command replacing "console.log". In that way I will be able to get records which I want, in the format which I like. Is there such a command(s)? Jul 4, 2016 at 9:54
  • wondering about the same thing..
    – TMOTTM
    Jul 10, 2016 at 10:32

The Geth console is basically a subset of Javascript, so you are limited to console.log and @Roland's answer of redirecting to a file could be done.

You have more flexibility by using Ethereum JSON-RPC (see filters). You can use a wide range of languages for JSON-RPC (some here) and its capabilities for I/O: for example you can use Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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