[Ethereum] How to automatically run a geth startup script and get a console


I would like to start geth using a startup script to automatically unlock the accounts and start the miner, and possibly other tasks (for my test network).

I tried the --exec 'loadscript('sript.js')' console and it runs the script and then exits. I tried js script' console and it runs the script, but doesn't give me a console.

I'd like to run a script AND get the console. How do I do this?

I'm running a frontier release version of geth (whatever the latest 'main' is) plus a patch to speed it up for test networks.

Best Answer

You can accomplish this with Geth's command line arguments in a startup script. Startup scripts will vary based on OS, but here is the general idea:

geth --unlock 0 --password "path/to/password/file" console

Below is another example of a command to unlock an account, start a miner, and log the results to a logfile. Example is found here.

geth --datadir /tmp/eth/42 --port 30342 --password <(echo -n notsosecret) --unlock primary --minerthreads 4 --mine 2>> /tmp/eth/42.log

In the above example you can also add console to the end of it to automatically put you in the console.

Remember to mind your slashes /\ when you are using different operating systems. Generally Windows paths have backwards slashes ("\") and Unix, Linux, and Mac systems have forward slashes ("/") when typing a file/folder path.

Related Topic