2

If I've programId (Pubkey) of a program, is it possible to get AccountInfo (or Program) object somehow?

Or conversely, is it possible to somehow invoke a (view) method on program if its programId is known?

1 Answer 1

3

Accounts can't be loaded on the runtime, rather they can only be pre-loaded and passed unto it. You'd have to pass in all the accounts you need(or think you might need) in from the client. There's no other way to access an account's data.

is it possible to somehow invoke a (view) method on program if its programId is known?

If such a method existed it would still need to be passed all the accountInfos it needs. One of those would need to be the accountInfo of the program, which would defeat the purpose. As of now there's simply no way on Solana to access an account's info without loading it pre-execution.

2
  • Interesting.. and it seems a bit ironic as well, because on the client side, we can ask nodes to get the account info, but solana-programs cannot do that, even though they run on the nodes themselves. Ideally, they should be the ones who should be able to get these data quickly. The solana world seems to be upside-down! Commented May 10, 2023 at 14:02
  • 1
    Haha yeah. It sure makes life as a solana developer more painful, but is partly the reason for Solana's performance. Here are some links to short posts that might be helpful in understanding how: twitter thread. medium article. blog.
    – Ademola
    Commented May 10, 2023 at 17:16

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.