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.

4 Answers 4


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.

  • that solves the immediate problem of getting accounts unlocked and miners started but if I need to do something not supported on the geth command line I'd be out of luck.
    – Paul S
    Commented Feb 15, 2016 at 18:41
  • 1
    geth command line also supports the js flag, which can js executes JavaScript files in the Geth JavaScript VM. If you have a program that you cannot run on the geth command line, maybe just have multiple start-up scripts? Commented Feb 15, 2016 at 19:24
  • Yes but when you run the js flag you don't get a console Want to run a startup script AND get the console.
    – Paul S
    Commented Feb 16, 2016 at 0:42
  • In a second console window, run geth attach console after the first start-up script runs. That will attach your geth instance to the 2nd command prompt. Commented Feb 16, 2016 at 3:17

Not possible. (Without seriously modifying geth.) It either runs your js, or you get a console. Here is the code that controls this. (or see below) .batch() below takes a js string and .interactive() gives a prompt.

if ctx.GlobalString(utils.ExecFlag.Name) != "" {
} else {
  • 1
    Ouch. Well, I guess I make a script that runs geth in the background and a second that attaches to it to run the startup script?
    – Paul S
    Commented Feb 13, 2016 at 2:57
  • If attaching to geth is a viable solution for you, you might wish to consider posting your own answer to show other users how it worked out for you @PaulS.
    – q9f
    Commented Feb 14, 2016 at 9:35
  • I have to have this working in about a week, so I'll post a solution then
    – Paul S
    Commented Feb 16, 2016 at 0:42
  • Is there a solution to this issue? Commented Jan 3, 2019 at 14:47

Windows system: You can pipe to a log file and keep your console uncluttered. I use baretail - https://www.baremetalsoft.com/baretail/ for real time logging display as well as a startup script/bat file to initiate geth. My bat file contains something like this for the ropsten testnet: "C:\path\to\gethfile\geth.exe" --testnet --networkid 3 --identity "GETH DEVELOP ROPSTEN" --datadir C:\path\to\ethereum_develop_ropsten\testnet_data --fast --jspath "c:\path\to-js\javascript" --cache=1048 --unlock "0, 1, 2, 3" --shh --rpc --rpcaddr= --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3 --ipcapi admin,db,debug,eth,miner,net,personal,shh,txpool,web3 --rpcport 8545 --verbosity 3 --password "C:\path\to\password.txt" --minerthreads "2" --rpccorsdomain "*" --solc "C:\path\to\solc.exe" console 2>> C:\path\to\GETH_DEVELOP_ROPSTEN_CONSOLE.log 2^&1


Look up the --preload {js filename} option in the Go-Ethereum Wiki. This will run a javascript file using Geth's JSRE.

This can be used with the console option, so that it runs a script AND provides a console. Personally, I use it to run a script to give me sync statistics along with the normal console output, but it could equally well unlock accounts at startup.

The option can also run a list of scripts. Just comma-separate them after --preload.

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.