0

language : python 3.7
network : kovan
use web3(infura)


I want to check the balance as well as the pending transaction.
The address below is the address with the Pending transaction.
Testing in the Kovan network may include or exclude fending as follows.

Do you know why?

address = '0x1Dcc3E38d55aac34C5e20Aa74da53a4F56Aa4189'
for x in range(5):
    data = w3.eth.getBalance(address, 'pending')
    print(data)
ssh://centos@192.168.0.132:22/data/venv/python3/bin/python -u /data/wallet_test/web3_test.py
1514315008999999959
1514315008999999959
2450527368999999961
2450527368999999961
2450527368999999961

enter image description here

1

This is probably a bad idea.

First, the "pending" transactions are subjective from the perspective of each node. They can only report transactions they know about.

You have seen that yourself.

Testing in the Kovan network may include or exclude pending as follows

Second, pending transactions are not reliably confirmed. They can be cancelled by the sender.

This is not normally a problem because there is no financial incentive to mislead and transactions are usually only cancelled for technical reasons, e.g. the gasPrice was too low and they have been in an unconfirmed state for too long.

On the other hand, if pending transactions are treated similarly to confirmed transactions, you may be opening up users to attack. If any decision or logic is based on a misplaced belief in the certainty of a pending transaction, there will be a financial incentive to load up the pending transactions with bogus transactions.

An exception to this is the sender themselves. I see no reason why a sender should not see their actual balance, less pending sent transactions for a net balance. In this case, the sender should know what they sent. Trusting their own records, there is no need to ask the node for anything.

A receiver could similarly see pending receipts but, for emphasis, nothing should imply certainty or reliability in the unconfirmed realm. You have discovered the way to do that, with the caveats described. The right thing to do is usually to wait for several confirmations.

Hope it helps.

  • Thank you. How long does it take for the pending to be included in the block? – 이경언 Oct 1 at 3:48
  • It depends on gas price bid which is like an auction for priority. Blocks are every 15 seconds. Propagation takes a few seconds. Conservatively estimated < 2 minutes over here: ethgasstation.info. The site helps folks adjust for network conditions. – Rob Hitchens - B9lab Oct 1 at 5:40

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.