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?

Lee
  • 8,548
  • 6
  • 46
  • 80
  • 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. – Tjaden Hess Jan 27 '17 at 17:30
  • @TjadenHess force of habit mainly... it has worked ok up to now. – Lee Jan 27 '17 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. – Tjaden Hess Jan 27 '17 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 '17 at 18:13
  • 1
    Found it here: http://ethereum.stackexchange.com/questions/9938/unable-to-connect-ethereum-node-even-rpc-port-8545-is-open – Lee Jan 27 '17 at 18:30

1 Answers1

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);
Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118