import {PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction,} from '@solana/web3.js'; export const TOKEN_METADATA_PROGRAM_ID = new PublicKey( 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s', ); export const SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = new PublicKey( 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', ); export const TOKEN_PROGRAM_ID = new PublicKey( 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', ); export const createAssociatedTokenAccountInstruction = ( associatedTokenAddress: PublicKey, payer: PublicKey, walletAddress: PublicKey, splTokenMintAddress: PublicKey, ) => { const keys = [ { pubkey: payer, isSigner: true, isWritable: true, }, { pubkey: associatedTokenAddress, isSigner: false, isWritable: true, }, { pubkey: walletAddress, isSigner: false, isWritable: false, }, { pubkey: splTokenMintAddress, isSigner: false, isWritable: false, }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false, }, { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false, }, { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false, }, ]; return new TransactionInstruction({ keys, programId: SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID, data: Buffer.from([]), }); }; export const createMetadataInstruction = ( metadataAccount: PublicKey, mint: PublicKey, mintAuthority: PublicKey, payer: PublicKey, updateAuthority: PublicKey, txnData: Buffer, ) => { const keys = [ { pubkey: metadataAccount, isSigner: false, isWritable: true, }, { pubkey: mint, isSigner: false, isWritable: false, }, { pubkey: mintAuthority, isSigner: true, isWritable: false, }, { pubkey: payer, isSigner: true, isWritable: false, }, { pubkey: updateAuthority, isSigner: false, isWritable: false, }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false, }, { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false, }, ]; return new TransactionInstruction({ keys, programId: TOKEN_METADATA_PROGRAM_ID, data: txnData, }); }; export const createMasterEditionInstruction = ( metadataAccount: PublicKey, editionAccount: PublicKey, mint: PublicKey, mintAuthority: PublicKey, payer: PublicKey, updateAuthority: PublicKey, txnData: Buffer, ) => { const keys = [ { pubkey: editionAccount, isSigner: false, isWritable: true, }, { pubkey: mint, isSigner: false, isWritable: true, }, { pubkey: updateAuthority, isSigner: true, isWritable: false, }, { pubkey: mintAuthority, isSigner: true, isWritable: false, }, { pubkey: payer, isSigner: true, isWritable: false, }, { pubkey: metadataAccount, isSigner: false, isWritable: false, }, { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false, }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false, }, { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false, }, ]; return new TransactionInstruction({ keys, programId: TOKEN_METADATA_PROGRAM_ID, data: txnData, }); }; export const createUpdateMetadataInstruction = ( metadataAccount: PublicKey, payer: PublicKey, txnData: Buffer, ) => { const keys = [ { pubkey: metadataAccount, isSigner: false, isWritable: true, }, { pubkey: payer, isSigner: true, isWritable: false, }, ]; return new TransactionInstruction({ keys, programId: TOKEN_METADATA_PROGRAM_ID, data: txnData, }); };