So I'm creating a Token2022 token for testing purposes right now, and I want to use the withdraw fee extension to hold a percentage on transfer and use my withdrawal authority account to capture those held fees into my account and use them for other purposes. This all works as expected, but I notice on certain occasions, the logic I have for creating a destination account for the token, and use that in the transfer instruction, sometimes it'll error out and say Error processing Instruction 0: incorrect program id for instruction
. But it'll only do this 3 or 4 times before the transaction goes through.
Could this be a devnet issue, an RPC issue, or could this be related to priority fees? The Token-2022 program ID I'm passing down is definitely the correct one, so I'm not sure. This is part of the hook I wrote.
const transferWithFee = async(): Promise<void> => {
try {
const token = new PublicKey('')
const sourceAccount = new PublicKey('')
const accountKeypair = Keypair.generate();
const destinationAccount = await createAccount(
connection,
owner,
token,
owner.publicKey,
accountKeypair,
undefined,
TOKEN_2022_PROGRAM_ID
);
const transferAmount = BigInt(1000 * Math.pow(10, decimals)); // Transfer 1000 tokens
const calcFee = (transferAmount * BigInt(feeBasisPoints)) / BigInt(10000); // expect 50 fee
const fee = calcFee > maxFee ? maxFee : calcFee;
const transaction = new Transaction().add(
createTransferCheckedWithFeeInstruction(
sourceAccount,
token,
destinationAccount,
sourceAccountOwner.publicKey,
transferAmount,
decimals,
fee,
[],
TOKEN_2022_PROGRAM_ID
)
);
const sig = await sendAndConfirmTransaction(connection, transaction, [payer, sourceAccountOwner]);
console.log('transfer sig: ', sig)
} catch ( error ) {
console.log('error minting and/or transferring token: ', error)
}
}