I'm not sure if something has updated recently, but code I am using has stopped working.
// Prepare metadata
const metaData: TokenMetadata = {
updateAuthority: mintAuthority,
mint: mint,
name: tokenMetadata.tokenName,
symbol: tokenMetadata.symbol,
uri: uri,
additionalMetadata: [["description", tokenMetadata.description]],
};
const mintExtensions = [ExtensionType.MetadataPointer];
if (isSupplyLimiterOn) mintExtensions.push(ExtensionType.TransferHook);
if (isTaxOn) mintExtensions.push(ExtensionType.TransferFeeConfig);
const metadataExtension = TYPE_SIZE + LENGTH_SIZE;
const metadataLen = pack(metaData).length;
const mintLen = getMintLen(mintExtensions);
const lamports = await connection.getMinimumBalanceForRentExemption(
mintLen + metadataExtension + metadataLen
);
// Create instructions
const instructions = [
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 3.33 * 1e6 }),
ComputeBudgetProgram.setComputeUnitLimit({
units: isSupplyLimiterOn ? 250_000 : 200_000,
}),
SystemProgram.createAccount({
fromPubkey: mintAuthority,
newAccountPubkey: mint,
space: mintLen,
lamports,
programId: TOKEN_2022_PROGRAM_ID,
}),
];
if (isTaxOn) {
const withdrawWithheldAuthority = new PublicKey(
taxWallet || mintAuthority
);
const feeBasisPoints = Number(taxPercent) * 100;
const maxFee = BigInt(tokenMetadata.supply * 10 ** decimals);
instructions.push(
createInitializeTransferFeeConfigInstruction(
mint,
mintAuthority,
withdrawWithheldAuthority,
feeBasisPoints,
maxFee,
TOKEN_2022_PROGRAM_ID
)
);
}
instructions.push(
createInitializeMetadataPointerInstruction(
mint,
mintAuthority,
mint,
TOKEN_2022_PROGRAM_ID
),
createInitializeMintInstruction(
mint,
decimals,
mintAuthority,
mintAuthority,
TOKEN_2022_PROGRAM_ID
),
createInitializeInstruction({
programId: TOKEN_2022_PROGRAM_ID,
metadata: mint,
updateAuthority: mintAuthority,
mint: mint,
mintAuthority: mintAuthority,
name: metaData.name,
symbol: metaData.symbol,
uri: metaData.uri,
}),
createUpdateFieldInstruction({
programId: TOKEN_2022_PROGRAM_ID,
metadata: mint,
updateAuthority: mintAuthority,
field: metaData.additionalMetadata[0][0],
value: metaData.additionalMetadata[0][1],
})
);
if (isSupplyLimiterOn) {
const [extraAccountMetaListPDA] = PublicKey.findProgramAddressSync(
[
Buffer.from("extra-account-metas"),
mintKeypair.publicKey.toBuffer(),
],
supplyProgramId
);
const [configPDA] = PublicKey.findProgramAddressSync(
[Buffer.from("config"), mintKeypair.publicKey.toBuffer()],
supplyProgramId
);
instructions.push(
createInitializeTransferHookInstruction(
mintKeypair.publicKey,
wallet.publicKey,
supplyProgramId,
TOKEN_2022_PROGRAM_ID
)
);
const maxWallet = Math.min(
Math.max(Number(maxWalletPercent) || 100, 0),
100
);
const maxTax = Math.min(
Math.max(Number(maxTransactionPercent) || 100, 0),
100
);
const supplyHookIx = await createSupplyHook(
wallet.publicKey,
mint,
extraAccountMetaListPDA,
configPDA,
maxWallet * 10000,
maxTax * 10000
);
instructions.push(supplyHookIx);
}
const userATAKey = getAssociatedTokenAddressSync(
mint,
mintAuthority,
true,
TOKEN_2022_PROGRAM_ID
);
instructions.push(
createAssociatedTokenAccountIdempotentInstruction(
mintAuthority,
userATAKey,
mintAuthority,
mint,
TOKEN_2022_PROGRAM_ID
),
createMintToInstruction(
mint,
userATAKey,
mintAuthority,
BigInt(tokenMetadata.supply * 10 ** tokenMetadata.decimals),
undefined,
TOKEN_2022_PROGRAM_ID
)
);
const globalAddressLookupTableAddress = new PublicKey(
"HXymiEoZzgb5emVa1NLexeMqmwx1wQegTB3dN6Yh8x1i"
);
const lookupTableAccount = (
await connection.getAddressLookupTable(globalAddressLookupTableAddress)
).value;
const blockhash = await connection.getLatestBlockhash();
const messageV0 = new TransactionMessage({
payerKey: wallet.publicKey,
recentBlockhash: blockhash.blockhash,
instructions,
}).compileToV0Message([lookupTableAccount!]);
const transaction = new VersionedTransaction(messageV0);
transaction.sign([mintKeypair]);
const signedTransaction = await wallet.signTransaction!(transaction);
const signature = await connection.sendRawTransaction(
signedTransaction.serialize(),
{ skipPreflight: true }
);
await connection.confirmTransaction({
signature,
blockhash: blockhash.blockhash,
lastValidBlockHeight: blockhash.lastValidBlockHeight,
});
This exact code worked for a long time but noticed recently I receive this error when attempting to deploy if I enable "supply limiter" to utilize my transferhook.
#5 - Token 2022 Program: initializeMint (Program Error: "invalid account data for instruction")