Why is getTransactionReceipt() returning None (NoneType object)?

0 votes

I am using the following code:

provider = HTTPProvider('http://0.0.0.0:9945')
w3 = Web3(provider)

contract = w3.eth.contract(contract_interface['abi'], bytecode=contract_interface['bin'])

tx_hash = contract.deploy(transaction={'from': w3.eth.coinbase, 'gas': 250000})

print (tx_hash)
time.sleep(1)
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
print (tx_receipt)
contract_address = tx_receipt['contractAddress']

The tx_hash variable is getting a valid valid but tx_receipt is getting none.

The error I am getting is as follows:
contract_address = tx_receipt['contractAddress']
TypeError: 'NoneType' object is not subscriptable

w3.eth.getTransactionReceipt(tx_hash) function returns None

I dont understand why. Please help.

Jul 24, 2018 in Blockchain by digger
• 26,550 points
105 views

1 answer to this question.

0 votes
By looking at your code, it seems like the code "(w3.eth.getTransactionReceipt(tx_hash)" is getting executed before the block has been mined. According to the getTransactionReceipt doc http://web3py.readthedocs.io/en/latest/web3.eth.html#web3.eth.Eth.getTransactionReceipt),
getTransactionReceipt returns None when the transaction has not yet been mined. The sleep(1) is not giving enough time for the
blocks to be mined.

If you are using geth, start mining by turning on --mine or else try while w3.eth.getTransactionReceipt(tx_hash) is None
answered Jul 24, 2018 by slayer
• 29,170 points

Related Questions In Blockchain

+1 vote
1 answer
0 votes
2 answers
0 votes
1 answer

Why is it downloading the blocks when I am trying to deploy the ethereum private network?

Once you have installed the Ethereum wallet, ...READ MORE

answered May 3, 2018 in Blockchain by Shashank
• 10,350 points
44 views
0 votes
1 answer

Why is Nubits faster than Bitcoin?

Different implementation of blockchain can have different ...READ MORE

answered Jul 11, 2018 in Blockchain by digger
• 26,550 points
25 views
0 votes
1 answer
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,550 points
81 views
+1 vote
1 answer
0 votes
1 answer

Where is the data stored in blockchain?

The smart contract is just the business ...READ MORE

answered Jun 29, 2018 in Blockchain by slayer
• 29,170 points
109 views
0 votes
1 answer

"const is reserved" parse error.

It could be an error because of ...READ MORE

answered Jul 6, 2018 in Blockchain by slayer
• 29,170 points
202 views