Search code examples
pythonpython-3.xweb3js

why web3.eth.getBlock gives null answer and getTransactionReceipt gives error?


I am using Web3.py in my python code. The code is like this

from web3 import Web3   
w3 = Web3(Web3.HTTPProvider("https://ropsten.infura.io/"))*  
for i in range(5000000,5100000):  
    print(i)  
    transactionArray = []  
    blockResult = w3.eth.getBlock(i)  
    for tx in blockResult["transactions"]:  
        txResult = binascii.hexlify(tx).decode()  
        print(txResult)
        transactionResult = w3.getTransactionReceipt(txResult)
        print(transactionResult)

When I execute this code, getting error

5000000  
Traceback (most recent call last):
  File "Test06.py", line 27, in <module>
    for tx in blockResult["transactions"]:
TypeError: 'NoneType' object is not subscriptable

but If I start range from 4571699 it gives me the result. Can somebody tell me why I'm getting an error for range starts from 5000000

I use the MAIN NET, so resolved this problem. But now I am getting an error as

Traceback (most recent call last):   
  File "Test06.py", line 35, in <module>
     transactionResult = w3.getTransactionReceipt(txResult)
AttributeError: 'Web3' object has no attribute 'getTransactionReceipt'.

Solution

  • You're using the ropsten test chain which only has 4572019 blocks as of this answer.