I created a wallet using this code :
from eth_account import Account
# Create a new Ethereum wallet
account = Account.create()
private_key = account.key.hex()
address = account.address
print("Private Key:", private_key)
print("Address:", address)
and then i sent a $0.01 worth ETH on basechain network. Now the transaction is visible on basescan but when i try to retrieve transactions using code it says no transactions.
import requests
import constants
wallet_address = '0x62103CFe6629F148eB6B4683449AD99049ACDe8F'
def fetch_transactions(address):
params = {
'module': 'account',
'action': 'txlist',
'address': address,
'startblock': 0,
'endblock': 99999999,
'sort': 'asc',
'apikey': constants.BASESCAN_API_KEY
}
response = requests.get('https://api.basescan.org/api', params=params)
data = response.json()
if data['status'] == '1':
transactions = data['result']
print(f'Transactions for address {address}:')
for tx in transactions:
print(f"Hash: {tx['hash']}, Block: {tx['blockNumber']}, From: {tx['from']}, To: {tx['to']}, Value: {tx['value']} ETH")
else:
print(f"Error fetching transactions: {data['message']}")
if __name__ == '__main__':
fetch_transactions(wallet_address)
Note that this code gives me correct transactions for another wallet address that is connected to metamask.