[Ethereum] How to get all address transactions

web3.py

I use Infura as a provider of HTTP.

But Infura does not allow you to make a filter.

requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed
for url: https://ropsten.infura.io/

Cannot create filter on Infura via web3.py

But it's very, very long to sort through the transactions of the whole network with this code:

from web3 import Web3, HTTPProvider

w3 = Web3(HTTPProvider('https://ropsten.infura.io/',
                       request_kwargs={'timeout': 60}))

def get_transaction_details(transaction):
    return w3.eth.getTransaction(transaction)

def get_address_transactions(address):
    i = 0
    while i < w3.eth.blockNumber:
        block = w3.eth.getBlock(i)
        for transaction in block.transactions:
            detail = get_transaction_details(transaction)
            print(detail)
        i += 1

How do I get all address transactions?

Best Answer

This solution seem very ineficient. You should use instead websocketprovider (ws), which will give filtering functionality using infura.

var ws_provider = 'wss://mainnet.infura.io/ws' 
var web3 = new Web3(new Web3.providers.WebsocketProvider(ws_provider))

hope this helps

Related Topic