1

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, '12345678');

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

console.log(eth.getTransaction(tx));

And run it with from bash:

local SCRIPT=${1:-web3.js}
geth --dev --mine --rpc --rpcaddr "0.0.0.0" --rpcapi "admin,debug,miner,shh,txpool,personal,eth,net,web3" &
local PID=$!

sleep 3

node "$SCRIPT"

sleep 1
kill -s 9 $PID

Nodejs 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 the block and how to check it's added/rejected?

0

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? – Paul Rumkin Oct 25 '16 at 9:54

Your Answer

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

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