Skip to content

Instantly share code, notes, and snippets.

@xeroc
Created May 13, 2025 10:20
Show Gist options
  • Save xeroc/7f0374171c4fcd216378f956b48006ea to your computer and use it in GitHub Desktop.
Save xeroc/7f0374171c4fcd216378f956b48006ea to your computer and use it in GitHub Desktop.
Load addresses from Solana Address Lookup Table using python
from solana.rpc.async_api import AsyncClient
from solana.rpc.commitment import Confirmed
from solders.pubkey import Pubkey
# The serialized size of lookup table metadata
LOOKUP_TABLE_META_SIZE = 56
LOOKUP_TABLE_MAX_ADDRESSES = 256
async def get_lookup_table_addresses(connection, lookup_table_address):
"""
Retrieve the content of a Solana Address Lookup Table
:param connection: Solana RPC connection
:param lookup_table_address: Pubkey of the lookup table
:return: Lookup table details
"""
try:
# Fetch the lookup table account
lookup_table_account = await connection.get_account_info(
lookup_table_address, commitment=Confirmed
)
if not lookup_table_account.value:
print(f"No account found for address: {lookup_table_address}")
return None
# Get the raw account data
account_data = lookup_table_account.value.data
if account_data[0] != 1:
print("Not a valid lookup table account")
return None
addresses = list()
# Extract number of addresses (little-endian 32-bit integer)
for i in range((len(account_data) - LOOKUP_TABLE_META_SIZE) // 32):
start = LOOKUP_TABLE_META_SIZE + (i * 32)
end = start + 32
address = Pubkey(account_data[start:end])
addresses.append(address)
# print("Lookup Table Details:")
# print(f"Number of Addresses: {len(addresses)}")
return addresses
except Exception as e:
print(f"Error retrieving lookup table content: {e}")
return None
# Example usage
async def main():
# Replace with your RPC endpoint (e.g., QuickNode, Alchemy, etc.)
CONNECTION_URL = "https://api.mainnet-beta.solana.com"
# Replace with the actual lookup table address you want to inspect
LOOKUP_TABLE_ADDRESS = "4U91e8bbHM6RzSxtRYbogSyWJWtQKTvUkbVxZoBGhgTp"
# Create async connection
async with AsyncClient(CONNECTION_URL) as connection:
# Get lookup table content
addresses = await get_lookup_table_addresses(
connection, Pubkey.from_string(LOOKUP_TABLE_ADDRESS)
)
if addresses:
print("\nAddresses in Lookup Table:")
for idx, address in enumerate(addresses, 1):
print(f"{idx}. {address}")
# Run the async main function
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment