there are arguments
"args": [
{
"name": "decimals",
"type": "u8"
},
{
"name": "mintAuthority",
"type": "publicKey"
},
{
"name": "freezeAuthority",
"type": {
"defined": "COption<Pubkey>"
}
}
]
How to make the correct schema to be used in borsh.js?
I tried something like this
const schema = {
struct: {
decimals: "u8",
mintAuthority: "string",
freezeAuthority: "string",
},
};
or
class MyArgs {
decimals: u8;
mintAuthority: PublicKey;
freezeAuthority: COption<Pubkey> | null;
constructor(decimals: u8, mintAuthority: PublicKey, freezeAuthority: COption<Pubkey> | null) {
this.decimals = decimals;
this.mintAuthority = mintAuthority;
this.freezeAuthority = freezeAuthority;
}
}
const MyArgsSchema = new Map([
[
MyArgs,
{
kind: 'struct',
fields: [
['decimals', 'u8'],
['mintAuthority', 'publicKey'],
['freezeAuthority', { kind: 'option', type: 'publicKey' }],
],
},
],
]);
const data = "bT1LdJiCtzLAHMaiFmacn9H5oEZbRNsD6un3YxFXLYX6aixPPcaebNgLjwnMxzsEQ7uHaVmG3f5MPax7VEPAbJXYY1Q";
const resultDecode = deserialize(
MyArgsSchema, // MyArgsSchema or schema
Buffer.from(bs58.decode(data)),
);
console.log(resultDecode); // Error Invalid schema....
but it threw an error
Error: Invalid schema: {} expected option, enum, array, set, map, struct or u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, f32, f64, bool, string
How to correctly specify the type for publicKey
and
"type": {
"defined": "COption<Pubkey>"
}
i`m use "borsh": "^2.0.0" version, "bs58": "^5.0.0",