5
votes
Accepted
Program cannot deserialize borsch serialized instruction from typescript client
First correct your schema declaration:
// Instruction variant indexes
enum InstructionVariant {
InitializeAccount = 0,
Deposit,
Withdraw,
}
const DepositSchema = new Map([
[
...
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 ...
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,
...
3
votes
Accepted
Borsh dependency issue with latest versions of crates
You can’t use anchor 28 with mpl token metadata until Metaplex updates their libraries. Downgrade to anchor 26 with Solana 1.14
Check the Anchor issues for more info
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 ...
2
votes
Accepted
Rust Client - Get Serum liquidity pool info
I think you are getting confused as to what Serum pools are. The code in your link is some sort of agnostic pool which doesn't define a swap capability.
If you read the spl-token-swap documentation &...
2
votes
Accepted
Persistent negative offset span value when serialising a structure in Borsh generated by Anchor
As you noted, that -1 span is due to the variable-length fields in your type, the Strings. Instead, you can change your types to encode a set number of bytes in utf-8 encoding, e.g.:
const STRING_LEN:...
2
votes
Program cannot deserialize borsch serialized instruction from typescript client
this is another solution that worked for me
function DepositInstructionData(deposit_amount): Buffer {
const dataLayout = BufferLayout.struct([
BufferLayout.u8('instruction'),
...
2
votes
Program cannot deserialize borsch serialized instruction from typescript client
amount is declared as u64 in the Rust program, but only u8 on the client side schema. All type declarations must match in both size and layout on both sides
2
votes
Borsh Deserialization error: Trying to access beyond buffer length
Since your struct has variable-length fields (strings), using the struct type will be very difficult, since it can't calculate the size of each field statically.
There should be an easier way, however....
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 ...
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 ...
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: ...
2
votes
Accepted
What is the difference between `serialize`,`try_to_vec` and `try_serialize` in anchor?
No, they are not. try_to_vec and serialize are quite similar as try_to_vec calls serialize under the hood. The difference between these two is that serialize requires you to pass a writer where the ...
2
votes
Accepted
Facing error with array/string serialization in anchor solana
Your Order struct in Rust has token_id defined as [u8; 80], meaning it expects a 80-byte array. If the serialized data for token_id doesn't match this length, Borsh will throw an error since it ...
1
vote
How to get same borsh serialize result for same input from both JS and Rust
I found the mistake I have made.
SHOULD use BorshSchema.Array(BorshSchema.u8, 32), for PubKey type data 'recipient', not BorshSchema.Vec(BorshSchema.u8)
1
vote
Deserializing Anchor Account Data
I haven’t tested anything but I’ve been researching and I think it comes down to anchor putting 8 bytes of discriminator data at the start of account data, so I’m going to slice the first 8 bytes off ...
1
vote
In a solana program, how do you go about (Borsh) deserializing account data where the allocated data size is bigger than the actual struct size?
Same issue although I tried using borsh0_10::try_from_slice_unchecked as the tooltip for the deprecated try_from_slice_unchecked suggested. But I get the the error that "the trait bound ...
1
vote
Accepted
Parsing instructions in Rust
The stake program is a bit unique because it doesn't have an IDL.
On the other hand, @solana/web3.js provides instruction decoders out of the box for you. Given the instruction data, you can do:
const ...
1
vote
Deserializing an Enum with borsh
I'm not sure what version of Borsh-JS you're using, but there's probably a way to "tag" the enum name. In the most recent version, that would look like:
const WhitelistMode = borsh.rustEnum([...
1
vote
Accepted
program return data to client error
meta.returnData.data is trimmed all of the least significant bit (LE) to the right from your program returned value. In this case, it's missing 3 zero bytes at the end of the buffer.
I think a better ...
1
vote
Borsh, pubkey & COption
In my Cargo.toml I was using borsh=0.10.3 and downgrading to borsh=0.9.3 fixed my problem.
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::...
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 ...
1
vote
Accepted
How does borsh serialize updated data back into account?
counter_ai is an AccountInfo object provided by the runtime to the program, and it contains the accounts lamports (SOL) as a mutable reference &mut u64 and data as a mutable slice of bytes &...
1
vote
How do you decode struct numbers for testing in anchor?
You can do
state.depositCap.eq(depositCap)
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
borsh × 30deserialization × 10
anchor × 9
solana-program × 6
serialization × 6
web3.js × 4
account × 3
anchor-client × 3
rust × 2
getprogramaccounts × 2
idl × 2
decode × 2
account-data × 2
solana-sdk × 2
pda × 1
python × 1
javascript × 1
instructions × 1
candy-machine-v2 × 1
data × 1
anchor-program-idl × 1
buffer × 1
serum × 1
buffer-layout × 1
iter × 1