3

I want to fetch an account's data using [Metaplex KT Library][1].

I am still facing error while fetching an account: code:

try {
             val serializer = SolanaAccountSerializer(BorshAsBase64JsonArraySerializer((ProgramInfo.serializer())))
                val account = solana.api.getAccountInfo(serializer, getProgramInfoPda().address).getOrThrow()

                Log.d(TAG, "fetchQuestionCount: ${account}")
            } catch (e: Exception) {
                Log.d(TAG, "fetchQuestionCount Error: ${e.message}")
         }

Context: ProgramInfo is my own class:

@Serializable
data class ProgramInfo(var author: @Contextual PublicKey, var question_count: @Contextual Number, var bump: @Contextual Number) {
}

This is the error: Error: Size must be known in advance when using READ_ALL

2
  • Did you check if the account exists? Can you send the address and network?
    – Jonas H.
    Commented Jul 3, 2023 at 10:22
  • @JonasH. Devnet 9eESgm63H5DvRvZNczdJ8HvHf2VoA93m5Rw6Y5QMu9Z Account exists Commented Jul 3, 2023 at 17:40

2 Answers 2

1

Hard to tell what the problem is, but maybe you need to use another Serializer. What kind of account is it? Anchor?
Then maybe

SolanaAccountSerializer

is what you are searching for.

3
  • how do i use this? Commented Jul 4, 2023 at 12:24
  • I was just looking this up in the kotlin sdk source code: github.com/… maybe give it a try.
    – Jonas H.
    Commented Jul 4, 2023 at 13:49
  • I did some edits and now i am getting different error. I am able to fetch a wallet account (as its data is null) Commented Jul 16, 2023 at 8:50
1

Try out sol4k for this. Getting account info can be done like this:

val usdc = PublicKey("Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr")
val connection = Connection(rpcUrl)
val accountInfo = connection.getAccountInfo(usdc)

Find the full example in this integration test.

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.