2

I try to monitor new transactions.

from web3.auto import w3
import time

l = w3.eth.filter('latest')

while True:
  ts = time.time()
  ll = l.get_new_entries()
  for i in ll:
      print('===== Block hash:  ', i.hex())
      block_hash = i.hex()
      block = w3.eth.getBlock(block_hash, full_transactions=True)
      transactions = block['transactions']
      print('===== Block Number: ', block['number'])
      for tx in transactions:
         print(ts, '   From wallet: ', tx['from'])
         print(ts, '   Value ETH: ', tx['value'])

The result for Ropsten test network was:

===== Block hash:   0x0297b09d64f5db2df68cf8dca56323bd6c021306fb9227e1a668b79155819bee
===== Block Number:  2081162
1548529910.8412573    From wallet:  0xFF8705243e84B8DAD8b0A25B7c76CFa48456e4D5
1548529910.8412573    Value ETH:  100000000000000000
1548529910.8412573    From wallet:  0x8eD3077e18D536d38d31c379e4f407540275876E
1548529910.8412573    Value ETH:  200000000000000000
1548529910.8412573    From wallet:  0xeDc3fbcf9F7F0E9dFD2Fc31bD8ad9BA1DD632322
1548529910.8412573    Value ETH:  0
1548529910.8412573    From wallet:  0xeDc3fbcf9F7F0E9dFD2Fc31bD8ad9BA1DD632322
1548529910.8412573    Value ETH:  0
1548529910.8412573    From wallet:  0xE49aEAaC12e3323d675669A3Da2ED018a7929a0B
1548529910.8412573    Value ETH:  0
===== Block hash:   0x2102996c79e7a599eb3ca0b9d13276c135193413128d95266d1b8ad503cd5cfe
===== Block Number:  2081163
1548529910.9399285    From wallet:  0x77F71e7C2Be802cc7f531d177647E07163c9c756
1548529910.9399285    Value ETH:  0

If latest block

2081163

then my first loop

While True:

gives me several transactions

1548529910.9399285 From wallet: 0x77F71e7C2Be802cc7f531d177647E07163c9c756 1548529910.9399285 Value ETH: 0

if this block is not closed by miners, then my second loop while True gives me next transactions from this block?

Or

l = w3.eth.filter('latest')
ll = l.get_new_entries()

works only after latest block closed by miners?

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.