Getting error:failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0xd
Code is:
import {
Connection,
Transaction,
clusterApiUrl,
sendAndConfirmTransaction,
} from "@solana/web3.js";
import {
ExtensionType,
TOKEN_2022_PROGRAM_ID,
createAccount,
createMint,
createReallocateInstruction,
createEnableRequiredMemoTransfersInstruction,
createInitializeTransferFeeConfigInstruction,
} from "@solana/spl-token";
// Playground wallet
const payer = pg.wallet.keypair;
// Connection to devnet cluster
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
// Transaction signature returned from sent transaction
let transactionSignature: string;
// Authority that can mint new tokens
const mintAuthority = pg.wallet.publicKey;
// Decimals for Mint Account
const decimals = 2;
// Create Mint Account
const mint = await createMint(
connection,
payer, // Payer of the transaction and initialization fees
mintAuthority, // Mint Authority
null, // Optional Freeze Authority
decimals, // Decimals of Mint
undefined, // Optional keypair
undefined, // Options for confirming the transaction
TOKEN_2022_PROGRAM_ID // Token Extension Program ID
);
// Create Token Account for Playground wallet
const tokenAccount = await createAccount(
connection,
payer, // Payer to create Token Account
mint, // Mint Account address
payer.publicKey, // Token Account owner
undefined, // Optional keypair, default to Associated Token Account
undefined, // Confirmation options
TOKEN_2022_PROGRAM_ID // Token Extension Program ID
);
// Extensions to reallocate data for
const extensions = [
ExtensionType.MemoTransfer,
ExtensionType.TransferFeeConfig,
];
// Instruction to reallocate Token Account data
const reallocateInstruction = createReallocateInstruction(
tokenAccount, // Token Account address
payer.publicKey, // Payer to reallocate data
extensions, // Extensions to reallocate
payer.publicKey, // Token Account owner
undefined, // Additional signers
TOKEN_2022_PROGRAM_ID // Token Extension Program ID
);
// Instruction to initialize the MemoTransfer Extension
const enableRequiredMemoTransfersInstruction =
createEnableRequiredMemoTransfersInstruction(
tokenAccount, // Token Account address
payer.publicKey, // Token Account Owner
undefined, // Additional signers
TOKEN_2022_PROGRAM_ID // Token Extension Program ID
);
const feeBasisPoints = 100; // 1%
const maxFee = BigInt(2 ** 228) - BigInt(1);
// Instruction to initialize Mint Account data
const initTransferFeeConfig = createInitializeTransferFeeConfigInstruction(
mint, // Mint Account address
payer.publicKey, // Authority to update fees
payer.publicKey, // Authority to withdraw fees
feeBasisPoints, // Basis points for transfer fee calculation
maxFee, // Maximum fee per transfer
TOKEN_2022_PROGRAM_ID // Token Extension Program ID
);
// Add instructions to new transaction
const transaction = new Transaction().add(
reallocateInstruction,
initTransferFeeConfig,
enableRequiredMemoTransfersInstruction
);
// Send Transactoin
transactionSignature = await sendAndConfirmTransaction(
connection,
transaction,
[payer]
);
console.log(
"\nReallocate:",
`https://solana.fm/tx/${transactionSignature}?cluster=devnet-solana`
);