0

This question already has an answer here:

I have started a geth client using the below client(I had already created two accounts.:

geth --datadir datadir --networkid 123 --rpc --rpcaddr="localhost" --rpccorsdomain="*" --unlock <my account> --minerthreads="1" --maxpeers=0 --mine console

I opened the the ethereum wallet and deployed the smart contract from there. The transactionId and the contract address is received on my geth console.

Then I started my Dapp and created the instances of the contract and I am calling the contract invoking a contract function through web3 API. The contract function gets invoked but the transaction does not get submitted in the block unless I start mining. Hence I started miner.start() This started mining numerous blocks.

My question is where are these blocks coming from if I have my own private net and have submitted only one transaction. This is adding too many blocks and my blocksize is increasing unnecessarily. How to mine only the transaction I have submitted?

marked as duplicate by eth Nov 24 '16 at 20:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

These blocks are mined by your client by using miner.start() the blocks are mined until your transaction got included in one of these blocks. To stop the operation tape miner.stop() even the log didn't give you the prompt. However, the best thing is using a script that mine only the pending transactions (you mine only few blocks until your transaction got mined).

such script will contain

var mining_threads = 1

    function checkWork() {
        if (eth.getBlock("pending").transactions.length > 0) {
            if (eth.mining) return;
            console.log("== Pending transactions! Mining...");
            miner.start(mining_threads);
        } else {
            miner.stop();
            console.log("== No transactions! Mining stopped.");
        }
    }
    console.log("checkWork() is defined");
    eth.filter("latest", function(err, block) { checkWork(); });
    eth.filter("pending", function(err, block) { checkWork(); });

    checkWork();

on geth use

 loadScript("C:/Users/Tera_pc/Desktop/demo/mine_pending.js")
  • Do I have to loadscript() for each transaction? – Lakshmi Nov 24 '16 at 15:35
  • I tried this; now the mining is taking too long time; I am not sure why it is so; I have develeoped a Dapp based on cryptocurrency ethereum example. when i am transferring the token to another account it is taking too long a time to get mined now. :( . Is this because the block size has increased? Currently the block size is 97. – Lakshmi Nov 24 '16 at 16:33
  • this doesn't have any relation with the block size, you need only to wait few seconds until your transaction got mined, you could instead using previous script use : miner.start(8); admin.sleepBlocks(10); miner.stop() ; you precise how many block to mine – Badr Bellaj Nov 24 '16 at 17:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.