0

This is my code. I don't understand what this error is for. My console shows the account data has been added to the array successfully.

for (const accountInfo of allAccounts) {
            const account = unpackAccount(
                accountInfo.pubkey,
                accountInfo.account,
                TOKEN_2022_PROGRAM_ID
            );
            const transferFeeAmount = getTransferFeeAmount(account);

            if (transferFeeAmount !== null && transferFeeAmount.withheldAmount > bigInt(0)) {
                accountsToWithdrawFrom.push(accountInfo.pubkey);
            }
        }

        
        console.log(accountsToWithdrawFrom);
        console.log(withdrawAccount)

        const ix = createWithdrawWithheldTokensFromAccountsInstruction({
            mint: new PublicKey(mint),
            destination: new PublicKey(withdrawAccount),
            authority: publicKey.value,
            signers: undefined,
            sources: accountsToWithdrawFrom, // Ensure accountsToWithdrawFrom is properly initialized
            programId: TOKEN_2022_PROGRAM_ID
        });

Screenshots of the error.

enter image description here

1 Answer 1

0

There may be other errors, but createWithdrawWithheldTokensFromAccountsInstruction takes the parameters one by one, and not as an object, so you should do:

        const ix = createWithdrawWithheldTokensFromAccountsInstruction(
            new PublicKey(mint),
            new PublicKey(withdrawAccount),
            publicKey.value,
            [],
            accountsToWithdrawFrom,
            TOKEN_2022_PROGRAM_ID
        );

Source code at https://github.com/solana-labs/solana-program-library/blob/d1c03cc6164ebdeebef19190de28b7a71f4e4cb6/token/js/src/extensions/transferFee/instructions.ts#L550 for reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.