ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.97k stars 1.69k forks source link

Transaction with hash: '0x407b866ac4f1083f15b6b25537a0938cfb1606a5b245032f82871c85097bb1ec' not found. #2294

Closed andres15alvarez closed 2 years ago

andres15alvarez commented 2 years ago
aiohttp==3.8.1
aiosignal==1.2.0
async-timeout==4.0.2
attrs==21.4.0
base58==2.1.1
bitarray==1.2.2
certifi==2021.10.8
charset-normalizer==2.0.10
cytoolz==0.11.2
eth-abi==2.1.1
eth-account==0.5.6
eth-hash==0.3.2
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.2.1
eth-typing==2.2.2
eth-utils==1.10.0
frozenlist==1.2.0
hexbytes==0.2.2
idna==3.3
ipfshttpclient==0.8.0a2
jsonschema==3.2.0
lru-dict==1.1.7
multiaddr==0.0.9
multidict==5.2.0
netaddr==0.8.0
parsimonious==0.8.1
protobuf==3.19.1
pycryptodome==3.12.0
pyrsistent==0.18.0
requests==2.27.1
rlp==2.0.1
six==1.16.0
toolz==0.11.2
urllib3==1.26.7
varint==1.0.2
web3==5.25.0
websockets==9.1
yarl==1.7.2

What was wrong?

The error: Transaction with hash: ''0x407b866ac4f1083f15b6b25537a0938cfb1606a5b245032f82871c85097bb1ec" not found but in etherscan the transaction exists: https://ropsten.etherscan.io/tx/0x407b866ac4f1083f15b6b25537a0938cfb1606a5b245032f82871c85097bb1ec

I'm using Infura as provider with web socket

# Python

import json
from collections import namedtuple
from typing import List

# Web3
from web3.exceptions import ContractLogicError
from web3 import Web3
from web3.datastructures import AttributeDict

# Settings
from .settings import (
    PROJECT_ID,
    ABI,
    ADDRESS
)

w3 = Web3(Web3.WebsocketProvider(f'wss://ropsten.infura.io/ws/v3/{PROJECT_ID}'))
abi = json.loads(ABI)
address = w3.toChecksumAddress(ADDRESS)
contract = w3.eth.contract(address=address, abi=ABI)
Owner = namedtuple('Owner', ['address', 'email'])
Transaction = namedtuple('Transaction', ['address', 'amount'])

def create_project(address: str, private_key: str, goal: int, owner_email: str, project_name: str) -> int:
    try:
        transaction = contract.functions.createProject(goal, owner_email, project_name)\
            .buildTransaction({
                'from': address,
                'nonce': w3.eth.getTransactionCount(address),
                'gasPrice': w3.eth.gas_price
            })
        t_signed = w3.eth.account.sign_transaction(transaction, private_key=private_key)
        t_hash = w3.eth.send_raw_transaction(t_signed.rawTransaction)
        tx_receipt = w3.eth.get_transaction_receipt(t_hash)
        event = contract.events.ProjectCreation().processReceipt(tx_receipt)
    except ContractLogicError as e:
        return
    else:
        return event[0].args.id

`


Note: We prefer to use issues to track our work. If you think you've encountered a bug in web3py or have a feature request, you're in the right place. If you have implementation or usage questions, please refer to our documentation and/or join the conversation on discord.

LefterisJP commented 2 years ago

Infura may be pruning their nodes. If the node is pruned then transactions older than a certain number of blocks may not be found.

fselmo commented 2 years ago

@andres15alvarez, I'm with @LefterisJP on this. For whatever reason Infura was not at the latest block. I can currently get the transaction receipt for that transaction hash so at the moment it is working. I'm going to close this as this isn't an issue with web3.py but feel free to re-open if you feel this is still relevant.

andres15alvarez commented 2 years ago

Perfect, thank very much to you both @fselmo @LefterisJP. I'm going to fix my code to handle this infura's problem.