0

I am currently going though the Solana development course and I try to adapt what I learn onto an Android application. Everything is going great so far but now I am stuck when I try to serialise/deserialise data. I've tried to use Kotlin serialization to convert my data class into ByteArray with the following code: Json.encodeToString(data).encodeToByteArray().

However I get an error saying that

' Program logged: "panicked at 'called Result::unwrap() on an Err value: Custom { kind: InvalidInput, error: "Unexpected length of input" }', src/instruction.rs:34:59"'

And when I try to deserialise the data as follow val movies = connection.getProgramAccounts( serializer = BorshAsBase64JsonArraySerializer(MovieDe.serializer()), account = PublicKey("CenYq6bDRB7p73EjsPEpiYN7uveyPUTdXkDkgUduboaN"), programAccountConfig = ProgramAccountConfig())

I've got the following error:

java.lang.OutOfMemoryError: Failed to allocate a 1866989584 byte allocation with 2097152 free bytes and 184MB until OOM, target footprint 10037792, growth limit 201326592

Would anybody have some advice on how to serialise/deserialise data on Android? Thanks in advance for your help and advice.

1 Answer 1

0

the way you are deserializing your data is incorrect. You need to use the data struct of the account to serialize/deserialize it.

You need to create a data struct or if you are using an open source program with typescript bindings, you can find the program account data structs in program/js/src/accounts. Example from Metaplex Hydra. Import this file into your code to get deserialized data:

import { accountBeet } from './location/of/beet'
const account = new PublicKey(account);
let { data } = (await connection.getAccountInfo(account)) || {};
const deserialize = accountBeet.deserialize(data)[0];

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.