Running geth --exec
starts an interpreter. It allows to run geth console commands.
I want to load a javascript function that runs continuously in background in geth. It basically continuously looks for pending transactions and if found, it mines them else doesn't mine continuously (empty blocks unnecessarily).
Currently, I have to manually mine every time and stop mining.
geth --jspath "/root/files/js" --exec 'eth.mining;loadScript("mine_pending_transactions.js");eth.mining;' --datadir=/root/.ethereum/devchain attach
However, I don't want to mine this manually. In order to automate this, I want to load the script and mine it, as if it's a something like background command that runs in the geth console interpreter.
but I learnt from this Stack-overflow post - (Executing custom javascript snippets through non-interactive console) that one needs to access the same interpreter.
Is there a way to do that? Even in case of non-interactive console? Couldn't find anything on official Ethereum documentation.
geth <all you option> js JS_SCRIPT_FILE
?. In the help message it is reportedjs Execute the specified JavaScript files
. You can write a Javascript file that run continuosly in background. I use a javascript file to create continuosly new transactions every x milliseconds. So you can securely achieve what you are looking for.<all you option>
? I'm sorry I didn't get that.geth js javascript_file
but in general you can also specify some options, such as datadir etc.geth js mine_pending_transactions.js
as you mentioned, I get an error -listen udp :30303: bind: address already in use
. Hence I tried to mention the datadir where my existing ethereum is in placegeth --jspath "/root/files/js" --datadir=/root/.ethereum/devchain js mine_pending_transactions.js
. But now it returnsdatadir already used by another process