4

I have an array myArray on the geth command line of 1000 elements. When I type myArray on the geth console, it prints to screen. I'd like to pipe this to a text file. My development setup uses testrpc and go-ethereum with analysis of post-scripts in Python.

At the moment I'm cutting and pasting from geth. I sense there may be a much better way of doing it, but can't seem to find an example on searching.

Is there a simple way to save an array to file from the go-ethereum javascript command line?

5
  • Is there any particular reason you're using the geth console as opposed to nodeJS and web3? The geth console is pretty limited compared Node. Jan 27, 2017 at 17:30
  • @TjadenHess force of habit mainly... it has worked ok up to now.
    – Lee
    Jan 27, 2017 at 17:34
  • 1
    The geth console is essentially just a stripped-down node console. All your scripts will still work in node, and you can actually use libraries and files. Jan 27, 2017 at 17:37
  • @TjadenHess do you happen to know how I'd start node with the equivalent of: geth attach rpc:http://localhost:8545? Thanks
    – Lee
    Jan 27, 2017 at 18:13
  • 1
    Found it here: ethereum.stackexchange.com/questions/9938/…
    – Lee
    Jan 27, 2017 at 18:30

1 Answer 1

6

The geth console doesn't seem like the best tool for the job. A better method would be to use NodeJS + web3.

Just follow these instructions to connect web3 to your testrpc, then you can use exactly the same script as before, but write to a file using

var fs = require('fs');
fs.writeFileSync("myfile.txt", myArray);
2
  • Crucial thing to add, to run same script, was var eth = web3.eth;
    – Lee
    Jan 27, 2017 at 19:01
  • N.b. nodejs+web3+testrpc is noticably slower than geth+testrpc, for my script.
    – Lee
    Jan 27, 2017 at 19:37

Your Answer

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

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