0

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()

1 Answer 1

0

If Pubkey is not available directly from the solana package, you may be using a newer version of solana-py, which requires types from the solders package. See the note at the README:

Note: This library uses many core types from the Solders package which used to be provided by solana-py itself. If you are upgrading from an old version and you're looking for something that was deleted, it's probably in solders now.

So to fix this, you just need to add solders to your project, then add:

from solders.pubkey import Pubkey

Then you'll be able to convert your string to a Pubkey with:

RAYDIUM_PROGRAM_ID = Pubkey.from_string("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8")

Your Answer

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

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