Closed GrimLothar closed 3 years ago
I would like to add my use case as well, I am using node environment with metaplex metadata , throwing error when serializing the metadata
That would answer my last question on wether borsh was node env only.
I have solved it myself , you might want to see if you have import and called borch.ts extend methods in common/src/util , metaplex extended custom writter and reader for those pubkey addresses
borsh.ts
:
import { PublicKey } from '@solana/web3.js';
import { BinaryReader, BinaryWriter } from 'borsh';
import basex from 'base-x';
export type StringPublicKey = string;
export const extendBorsh = () => {
(BinaryReader.prototype as any).readPubkey = function () {
const reader = this as unknown as BinaryReader;
const array = reader.readFixedArray(32);
return new PublicKey(array);
};
(BinaryWriter.prototype as any).writePubkey = function (value: PublicKey) {
const writer = this as unknown as BinaryWriter;
writer.writeFixedArray(value.toBuffer());
};
(BinaryReader.prototype as any).readPubkeyAsString = function () {
const reader = this as unknown as BinaryReader;
const array = reader.readFixedArray(32);
return basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').encode(array) as StringPublicKey;
};
(BinaryWriter.prototype as any).writePubkeyAsString = function (
value: StringPublicKey,
) {
const writer = this as unknown as BinaryWriter;
writer.writeFixedArray(basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(value));
};
};
extendBorsh();
In your metadata.ts
: export * from './borsh';
Like @Xavier59 and @ymc182 commented, looks like i forgot to include this file: https://github.com/metaplex-foundation/metaplex/blob/81023eb3e52c31b605e1dcf2eb1e7425153600cd/js/packages/common/src/utils/borsh.ts
Looks like reader
and writer
are being added to borsh in there
All good!
Hi! I'm trying to use the
deserializeUnchecked
method but it seems to be failing with this error, any idea what might be going on? Does borsh work in browsers or only node environments?!
Thank you