js code:

const Web3 = require('web3');
const web3 = new Web3();
const {eth, personal} = web3;

web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

personal.unlockAccount(eth.coinbase, '1234567890');

const tx = eth.sendTransaction({
  from: eth.coinbase,
  data: web3.toHex('Hello World'),


And run it with bash:

geth --dev \
--rpc --rpcaddr "" --rpcapi "admin,miner,txpool,personal,eth,net,web3" \
--mine &

sleep 3

node web3.js

sleep 1
kill -s 9 $GETH_PID

Node.js script output is:

{ blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
  blockNumber: null,
  from: '0xdfb1b9b8693366eb9044ffd8c00058abc904558b',
  gas: 90000,
  gasPrice: { [String: '20000000000'] s: 1, e: 10, c: [ 20000000000 ] },
  hash: '0x0b4f742149fc3018a168950b56786846da99675913dbc043971cbe25ac7792ac',
  input: '0x48656c6c6f20576f726c64',
  nonce: 2,
  to: null,
  transactionIndex: null,
  value: { [String: '0'] s: 1, e: 0, c: [ 0 ] } }

But sometimes there is no such transaction when I restart Geth. How long transactions need to be put into a block and how to check it's added/rejected?

1 Answer 1


before you getTransaction, check txpool.status.pending, see if pending = 0. larger than 0 means there are pending tansactions in your node.

or you can call eth.getBlock("pending"), see if your transaction is in the pending block.


only after the node mined successfully & with the transaction in the block, the transaction status will change from pending, and include in the chain. to make sure the transaction is valid, you'd better wait around 12 confirmations(blocks), thats around 3 minutes.

  • I've read about attack on ethereum which adds several seconds to each block generation. Is it sensetive? Can I calculate confirmation blocks insteed? Oct 25, 2016 at 9:54

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.