this is a really simple question but I can't seem to find an example to do it. In a rust client I am just doing the following:

let (user_data_account, _user_bump_seed) = Pubkey::find_program_address(&[&user_id.to_le_bytes()], &program);
let (user_id_map, _user_id_map_bump_seed) = Pubkey::find_program_address(&[&user_account.to_bytes()], &program);

where user_account is a PubKey, and user_id is a u64.

In python, I am trying to use https://michaelhly.github.io/solana-py/ but PubKey doesn't have a to_bytes method, and i'm not really sure what to do to be able to get the same program address as I would get from the rust code (the same goes for the U64 really..)

Anyone done this before? Thanks


2 Answers 2


I have previously answered this question here - https://solana.stackexchange.com/a/2739/486

import base58
byte_array = base58.b58decode('4YFq9y5f5hi77Bq8kDCE6VgqoAqKGSQN87yW9YeGybpNfqKUG4WxnwhboHGUeXjY7g8262mhL1kCCM9yy8uGvdj7')
json_string = "[" + ",".join(map(lambda b: str(b), byte_array)) + "]"

PublicKey does have what you're looking for: bytes(key)

Your Answer

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

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