I’m writing a solana program that creates a data account that stores a u32
:
state:
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey;
#[derive(Debug, BorshDeserialize, BorshSerialize, Clone)]
pub struct BoyncAuctionState {
pub caller_key: pubkey::Pubkey,
}
impl BoyncAuctionState {
pub const SERIALZED_SIZE: usize = 32;
}
I’m using @solana/web3.js to get and deserialize that data to be pretty printed, however the client throws:
BorshError: Unexpected 28 bytes after deserialized data
Client:
/**
* The state of data account managed by the program
*/
class BoyncAuction {
caller_key = 0;
constructor(fields: {caller_key: number} | undefined = undefined) {
if (fields) {
this.caller_key = fields.caller_key;
}
}
}
/**
* Borsh schema definition for accounts
*/
const BoyncAuctionSchema = new Map([
[BoyncAuction, {kind: 'struct', fields: [['caller_key', 'u32']]}],
]);
export async function prettyPrintBoyncAuctionState(): Promise<void> {
const accountInfo = await connection.getAccountInfo(boyncAuctionPubkey.publicKey);
if (accountInfo === null) {
throw 'Error: cannot find the greeted account';
}
const boyncAuctionData = borsh.deserialize(
BoyncAuctionSchema,
BoyncAuction,
accountInfo.data,
);
console.log(
greetedPubkey.toBase58(),
'has caller_key: ',
boyncAuctionData.caller_key,
);
}
Can anyone help me and point me to whatever I’m missing?
Thanks,
Daniel.