I am facing following error:- Error finding latest created pair: argument 'program': 'str' object cannot be converted to 'Pubkey' when i try convert string to PublicKey.. It starts giving me import error of :- from solana.publickey import PublicKey
i have tried to import PublicKey with many alternative ways. However, none has seemed to work. Any help in this regard will be appreciated.
#Here is the Code:-
from solana.rpc.api import Client
rpc_url = 'https://api.mainnet-beta.solana.com/' solana_client = Client(rpc_url)
RAYDIUM_PROGRAM_ID = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
def find_latest_created_pair(): try: raydium_accounts = solana_client.get_program_accounts(RAYDIUM_PROGRAM_ID)
latest_created_pair = max(
raydium_accounts,
key=lambda account: account.get('data', {}).get('created_at', 0)
)
print('Latest Created Pair:', latest_created_pair)
except Exception as e:
print('Error finding latest created pair:', e)
find_latest_created_pair()