Skip to main content
5 votes
Accepted

Transaction Serialization/Deserialization not matching

When a transaction is serialized, the writeable and signer bits are only stored once for each account, at their most promoted value as referenced by all instructions. This discards the individual ...
trent.sol's user avatar
  • 4,415
4 votes
Accepted

Recommended serialization library for dynamically sized objects

You wouldn't want to serialize an account within the runtime. For any meaningfully sized account, this will use up more compute units than you have. I have generally gotten away with just looking up ...
Nick Garfield's user avatar
4 votes
Accepted

Recommended way to get Co-ordinated cluster time off chain

You can get the timestamp of the last processed block quite easily if that's sufficient: const slot = await connection.getSlot({ commitment: 'processed' }); const timestamp = await connection....
Callum M's user avatar
  • 3,140
4 votes

Solana Deserialization

If that Payload struct is the only input that your program can receive, then this should work: #[derive(BorshDeserialize, BorshSerialize, Debug)] struct Payload { purchase_qty: u64, ...
Joe C's user avatar
  • 1,086
3 votes

Offline Transaction: Transaction signature verification failure?

Since your user first signs the transaction and then you sign with a private key in the backend, you may need to use partialSign. You may be getting the "Signature verification failed" error ...
john's user avatar
  • 7,467
3 votes

How to deserialized Anchor accounts in Rust

Anchor will handle this if the struct is from your crate, pub my_acc: Account<'info, SomeStruct> will decode for you. If you are using a struct from another crate, you can use: pub fn ...
Whiteseal's user avatar
  • 3,185
3 votes
Accepted

Am I allowed to use a BinaryHeap in an account?

You're correct that BinaryHeap is implemented in Borsh: https://github.com/near/borsh-rs/blob/9e6831628442036fe3183f8244da3973bd99e8f7/borsh/src/ser/mod.rs#L305 This means that you can safely use it ...
Jon C's user avatar
  • 15.9k
3 votes

Instruction Error after upgrading solana program

You will need to migrate the account. There's a full guide how to do this on the cookbook
C.OG's user avatar
  • 2,827
2 votes
Accepted

How to allot 1 bit space for boolean in Anchor program?

You can't - Solana charges rent in lamports per byte-year, meaning the minimum amount of storage you can rent is one byte anyway. More info on rent can be found here. Additionally, even if you could, ...
Ahri's user avatar
  • 4,167
2 votes
Accepted

is it automatically written data to a pda account once you serialise it's data buffer?

You need no more than the last line. The serialize method writes to the account you pass into its argument, updating it.
Ademola's user avatar
  • 3,833
2 votes

What does range full operator do in borsh serialize?

That's just another way of dereferencing to get the internal data in Rust. &mut account.data.borrow_mut()[..] and *account_info.data.borrow_mut() should get the same result. You could write that ...
acheron's user avatar
  • 2,591
2 votes
Accepted

Offline Transaction: Transaction signature verification failure?

In this flow, is it possible that when the user is signing the transaction, their wallet is automatically adding priority fee instructions and signing that version of the transaction? Therefore the ...
Blocklord's user avatar
2 votes

Issues with Using AnchorSerialize and AnchorDeserialize Traits

When you declare TokenInfo to contain a Mint and Token, it means that the data inside the mint and token are copied into your account. Typically, this is wasteful and inefficient because you'll use up ...
Jon C's user avatar
  • 15.9k
2 votes
Accepted

What's the difference of using Borsh and buffer layout to encode/decode?

Borsh is just a particular serialization format, given by the spec at https://borsh.io/. They also provide libraries for serializing and deserializing types based on that spec. Buffer layout is a JS ...
Jon C's user avatar
  • 15.9k
2 votes
Accepted

How to decode base64 response?

I'm assuming that you mean decoding the base 64 account data into something more understandable, like JSON. It depends on your program! Programs write bytes into accounts however they want. For ...
Jon C's user avatar
  • 15.9k
2 votes
Accepted

How to properly deserialize encoded transaction?

According to the error, you are sending decoding a versioned message, ie, The version generally signifies the specifics of the layout of the message or instructions in it, if put in normal terms. And ...
toastx's user avatar
  • 86
2 votes
Accepted

Decode account data

I found the answer. Instead of using: import { publicKey, u64, bool, u256, u128 } from '@solana/buffer-layout-utils'; import { u32, u8, struct} from '@solana/buffer-layout'; I used: import * as borsh ...
CryptoTioSam's user avatar
2 votes

how to make a proper schema for the arguments

Pubkey is not part of the borsh specification. It can be represented as a [u8; 32] instead. Should look something like: class MyArgs { decimals: u8; mintAuthority: PublicKey; freezeAuthority: ...
Ademola's user avatar
  • 3,833
2 votes
Accepted

Failed to serialize or deserialize account data: Unknown

In anchor, failure to deserialize an account happens sometimes when a program tries to write more data to an account than the account has space. It looks like your code example you don't actually ...
Henry E's user avatar
  • 3,050
1 vote

Not able to read the updated value in a Solana Data Account

Instead of manually deserializing the account data, try: const account = await program.account.greetingAccount.fetch( greetingAccount.publicKey ) Anchor can automatically deserialize ...
john's user avatar
  • 7,467
1 vote

anchor_lang::AccountDeserialize

If you're doing it by hand, your implementation of AnchorDeserialize is entirely up to you! The idea is that, given a bunch of bytes, you try to create an instance of Example out of it. So in your ...
Jon C's user avatar
  • 15.9k
1 vote

Deserialise getAccountInfo data from Rust rpcclient for a PDA from drift protocol

Looks like the User struct isn't serialized with Borsh on the drift side, hence deserialization that way will fail. It's a zero-copy account instead. Try using anchor's AccountLoader to deserialize ...
Ademola's user avatar
  • 3,833
1 vote
Accepted

How to deserialize VoteState account from on-chain program

You did all the right research! The VoteState struct is too big to deserialize on-chain because its size is greater than the stack size of any function in the VM, as evidenced by the error: Stack ...
Jon C's user avatar
  • 15.9k
1 vote
Accepted

Using u128 without sacrificing alignment 8

If [u8; 16] works for you, then you can trick Anchor into treating it as a u128 by creating a custom type with the same name, "u128". To not pollute the outer scope, you declare it in a ...
Serban's user avatar
  • 1,296
1 vote

Solana Deserialization

If you want to manually deserialize some struct (without Anchor), I suggest bytemuck, structs are Plain Old Data (POD): pub fn get_payload_from_bytes(v: &[u8]) -> &Payload{ bytemuck::...
Whiteseal's user avatar
  • 3,185
1 vote
Accepted

Data Account Cannot Be Deserialized

createAccountWithSeed just allocates the space and assigns it to the program, and no data is written, so you should always see all zeroes in the program. The failed deserialization likely means ...
Jon C's user avatar
  • 15.9k
1 vote

What's the best way to deserialize Anchor Account Data from AccountInfo?

Some people prefer the [..] syntax vs the double deref (both are confusing, imo). You might also use the ? operator over unwrap: let buf: &[u8] = &ctx.remaining_accounts[0]....
Whiteseal's user avatar
  • 3,185
1 vote

What's the best way to deserialize Anchor Account Data from AccountInfo?

You have to setup a rust client. Create new cargo package inside your program root directory. And make sure to import your program in your client package (Cargo.toml) Create new solana client ...
vicyyn's user avatar
  • 4,095
1 vote
Accepted

Is it possible to use type `char` in an account field / as funciton arguments?

A char in rust is not considered serializable by the Borsh spec which anchor uses. This is because a char is really an array of 4 bytes with many invalid values. Depending on your use case you can use ...
Buzzec's user avatar
  • 534
1 vote

Recommended way to get Co-ordinated cluster time off chain

There might be a cleaner way to do this but you can fetch the clock sysvar and the decode it using the following snippet: import { AccountInfo, PublicKey } from '@solana/web3.js' import { BN } from '...
kklas's user avatar
  • 156

Only top scored, non community-wiki answers of a minimum length are eligible