@@ -27,6 +27,15 @@ export const TOKEN_PROGRAM_ID: PublicKey = new PublicKey(
2727 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' ,
2828) ;
2929
30+ /**
31+ * Unfortunately, BufferLayout.encode uses an `instanceof` check for `Buffer`
32+ * which fails when using `publicKey.toBuffer()` directly because the bundled `Buffer`
33+ * class in `@solana/web3.js` is different from the bundled `Buffer` class in this package
34+ */
35+ function pubkeyToBuffer ( publicKey : PublicKey ) : typeof Buffer {
36+ return Buffer . from ( publicKey . toBuffer ( ) ) ;
37+ }
38+
3039/**
3140 * 64-bit value
3241 */
@@ -1300,9 +1309,9 @@ export class Token {
13001309 {
13011310 instruction : 0 , // InitializeMint instruction
13021311 decimals,
1303- mintAuthority : mintAuthority . toBuffer ( ) ,
1312+ mintAuthority : pubkeyToBuffer ( mintAuthority ) ,
13041313 option : freezeAuthority === null ? 0 : 1 ,
1305- freezeAuthority : ( freezeAuthority || new PublicKey ( ) ) . toBuffer ( ) ,
1314+ freezeAuthority : pubkeyToBuffer ( freezeAuthority || new PublicKey ( ) ) ,
13061315 } ,
13071316 data ,
13081317 ) ;
@@ -1544,7 +1553,7 @@ export class Token {
15441553 instruction : 6 , // SetAuthority instruction
15451554 authorityType : AuthorityTypeCodes [ authorityType ] ,
15461555 option : newAuthority === null ? 0 : 1 ,
1547- newAuthority : ( newAuthority || new PublicKey ( ) ) . toBuffer ( ) ,
1556+ newAuthority : pubkeyToBuffer ( newAuthority || new PublicKey ( ) ) ,
15481557 } ,
15491558 data ,
15501559 ) ;
0 commit comments