0

On the web3py EthereumTesterProvider blockchain, I send 2 ethers from the first test account to the second one. The python program ends normally but the transaction seems to fail :

  • the status of the transaction receipt ('status': 0), which I guess means failed.
  • the balance of the 2 accounts is not updated after the transaction.

pip config (windows 10) :

  • web3py (5.31.3)
  • eth-tester (0.8.0b3)

Code:

from web3 import Web3, EthereumTesterProvider
from pprint import pprint

w3 = Web3(EthereumTesterProvider())
print(f"{w3.isConnected() = }")

print(f"\n{w3.eth.get_balance(w3.eth.accounts[0]) = }")
print(f"{w3.eth.get_balance(w3.eth.accounts[1]) = }")

tx_hash = w3.eth.send_transaction(
    {
        'from': w3.eth.accounts[0],
        'to': w3.eth.accounts[1],
        'value': w3.toWei(2, 'ether'),
        'gas': 21000
    }
)
print(f"\n{tx_hash = }")

print("\ntx_receipt = ")
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
pprint(dict(tx_receipt))

print(f"\n{w3.eth.get_balance(w3.eth.accounts[0]) = }")
print(f"{w3.eth.get_balance(w3.eth.accounts[1]) = }")

Traces:

w3.isConnected() = True

w3.eth.get_balance(w3.eth.accounts[0]) = 1000000000000000000000000
w3.eth.get_balance(w3.eth.accounts[1]) = 1000000000000000000000000

tx_hash = HexBytes('0x72345d1c23a10ac3849e1f8e53b517da8200e58ab211ebaf44df732f6f8a29af')

tx_receipt = 
{'blockHash': HexBytes('0xadfcec5788a8757a5eed6aeee15c997a6b75a612fa4919a878b02a69d04f8a0c'),
 'blockNumber': 1,
 'contractAddress': '0xa0Beb7081fDaF3ed157370836A85eeC20CEc9e04',
 'cumulativeGasUsed': 21000,
 'effectiveGasPrice': 1000000000,
 'from': '0xaBbACadABa000000000000000000000000000000',
 'gasUsed': 21000,
 'logs': [],
 'state_root': b'\x00',
 'status': 0,    <========   failure  ==========
 'to': '0xaBbACaDaBA000000000000000000000000000001',
 'transactionHash': HexBytes('0x72345d1c23a10ac3849e1f8e53b517da8200e58ab211ebaf44df732f6f8a29af'),
 'transactionIndex': 0,
 'type': '0x2'}

w3.eth.get_balance(w3.eth.accounts[0]) = 1000000000000000000000000
w3.eth.get_balance(w3.eth.accounts[1]) = 1000000000000000000000000

Please also note that this code works with ganache when I change the instance of web3 like that :

w3 = Web3(Web3.HTTPProvider('HTTP://127.0.0.1:8545'))
u2gilles
  • 6,888
  • 7
  • 51
  • 75

0 Answers0