I am running my private blockchain using geth on my ubuntu server with following cmd then its working fine

geth --datadir ~/chaindata/ --networkid 45123 --verbosity 3 --rpc --port 30304 --rpcport 8545 --rpcaddr "<private IP>" --rpccorsdomain "<private IP>" --rpcapi "web3,eth,personal,net"  --preload "/home/ubuntu/scripts/mineWhenNeeded.js" --nodiscover  --gcmode archive  --allow-insecure-unlock console 2

But when I try to run it in background using following cmd then my miner is not working

nohup geth --datadir ~/chaindata/ --networkid 45123 --verbosity 3 --rpc --port 30304 --rpcport 8545 --rpcaddr "<private IP>" --rpccorsdomain "<private IP>" --rpcapi "web3,eth,personal,net"  --preload "/home/ubuntu/scripts/mineWhenNeeded.js" --nodiscover  --gcmode archive  --allow-insecure-unlock > ~/myLogs/bcLogs.out 2>&1 &

I am using following script to mine the blocks using -preload "/home/ubuntu/scripts/mineWhenNeeded.js" flag

var minimum_confirmations = 3;
var mining_threads = 1
var txBlock = 0
function checkWork() {
    if (eth.getBlock("pending").transactions.length > 0) {
        txBlock = eth.getBlock("pending").number
        if (eth.mining) return;
        console.log("  Transactions pending. Mining...");
        interval = setInterval(function () {
            if (eth.getBlock("latest").number < txBlock + minimum_confirmations) {
                if (eth.getBlock("pending").transactions.length > 0) txBlock = eth.getBlock("pending").number;
            } else {
                console.log(minimum_confirmations + " confirmations achieved; mining stopped.");
        }, 600)

eth.filter("latest", function (err, block) { checkWork(); });
eth.filter("pending", function (err, block) { checkWork(); });


How can we run geth in background with miners?

  • Did you look at the logs? Can you increase geth verbosity? – Ismael Apr 10 at 19:26
  • 1
    @Ismael I tried to increase verbosity to 6 but couldn't find any issue ...for some reason miners were not taking transactions... then I tried Screen instead of Nohup to run Geth in background and Screen worked for me...... – Ruchita Apr 10 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.