0

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?

2 Answers 2

2

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

0

I am actually working on an API that is much more convenient for this task compared to Infura.

Just run the request below (and replace the placeholder address 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D with the address you have in mind in both places).

This should get you all transactions for an address in a single request (if there are more than 100,000 transactions you can use the cursor to fetch the next page of results - docs here: syve.ai).

curl --location --request POST 'https://api.syve.ai/v1/transactions' \
--header 'Content-Type: application/json' \
--data-raw '{
        "filter": {
            "type": "or",
            "params": {
                "filters": [
                    {
                        "type": "eq",
                        "params": {
                            "field": "to_address",
                            "value": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
                        }
                    },
                    {
                        "type": "eq",
                        "params": {
                            "field": "from_address",
                            "value": "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
                        }
                    }
                ]
            }
        },
        "options" : [
            {
                "type" : "size",
                "params" : {
                    "value" : 100000
                }
            }
        ]
    }'
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Sky
    Commented Feb 24, 2023 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.