How do I get all incoming txs to an Eth address with a python script using Alchemy SDK?
- blockchain
- wallet All Things Web3
Expert
I have an Alchemy API python script that checks the balance for an Ethereum address. According to the python alchemy-sdk docs, you can set up the Alchemy API object like this:
from alchemy import Alchemy, Network
# create Alchemy object using your Alchemy api key, default is "demo"
api_key = "your_api_key"
# choose preferred network from Network, default is ETH_MAINNET
network = Network.ETH_MAINNET
# choose the maximum number of retries to perform, default is 5
max_retries = 3
# create Alchemy object
alchemy = Alchemy(api_key, network, max_retries=max_retries)
From here you can get the ether balance of an address like this:
eth_address_balance = alchemy.core.get_balance("ADDRESS", "BLOCK_NUMBER")
Notice that you can get the address balance at any block height by adding "BLOCK_NUMBER" to the get_balance
function.
How would I get all transactions that send ether to a certain address between 2 block heights?
I know your first instinct is to tell me to check Etherscan but I've noticed that some exchanges send ether to my address and no transaction appears on Etherscan... That's why I'm trying to build this script.