I am having this error when processing instructions for a transaction.
Detail error log:
Transaction simulation failed: Error processing Instruction 1: Provided owner is not allowed
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
Program log: Create
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]
Program log: Instruction: GetAccountDataSize
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1622 of 992908 compute units
Program return: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
Program 11111111111111111111111111111111 invoke [2]
Program 11111111111111111111111111111111 success
Program log: Initialize the associated token account
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]
Program log: Instruction: InitializeImmutableOwner
Program log: Please upgrade to SPL Token 2022 for immutable owner support
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 986418 compute units
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]
Program log: Instruction: InitializeAccount3
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4241 of 982534 compute units
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 22045 of 1000000 compute units
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
Program log: Create
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 5209 of 977955 compute units
Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: Provided owner is not allowed
This is how the instruction is constructed:
const provider = new anchor.AnchorProvider(connection, wallet as any, {});
const gameProgram = new Program(
gameIdl as Idl,
gameProgramId,
provider
);
const gameKeypair = anchor.web3.Keypair.generate();
const gameId = gameKeypair.publicKey;
const fixedGameKeypair = anchor.web3.Keypair.generate();
const [gameSigner, _bump] = await anchor.web3.PublicKey.findProgramAddress(
[gameKeypair.publicKey.toBytes()],
gameProgram.programId
);
const escrowTicketTokenAccount = await getAssociatedTokenAddress(
new PublicKey(ticketMint),
gameSigner,
true
);
const escrowPrizeTokenAccount = await getAssociatedTokenAddress(
new PublicKey(prizeMint),
gameSigner,
true
);
const ticketTokenAccount = await getAssociatedTokenAddress(
ticketMint,
wallet.publicKey
);
const prizeTokenAccount = await getAssociatedTokenAddress(
prizeMint,
wallet.publicKey
);
const initTokenAccountsInstruction = [
createAssociatedTokenAccountInstruction(
wallet.publicKey, // payer
escrowTicketTokenAccount, // ata
gameSigner, // owner
ticketMint // mint
),
createAssociatedTokenAccountInstruction(
wallet.publicKey, // payer
escrowPrizeTokenAccount, // ata
gameSigner, // owner
prizeMint // mint
),
];
const accounts = {
payer: wallet.publicKey,
ticketMint,
prizeTokenAccount,
prizeMint,
game: gameId,
gameSigner,
systemProgram: SystemProgram.programId,
tokenProgram: anchor.utils.token.TOKEN_PROGRAM_ID,
escrowPrizeTokenAccount,
fixedGame: fixedGameKeypair.publicKey,
};
const params = {
...args,
bump: _bump,
};
const tx = await gameProgram.methods
.createGame(params)
.accounts(accounts)
.preInstructions([
...initTokenAccountsInstruction,
SystemProgram.createAccount({
fromPubkey: wallet.publicKey,
newAccountPubkey: gameId,
programId: gameProgram.programId,
lamports: await connection.getMinimumBalanceForRentExemption(
8 + 32 * 4 + 8 * 9 + 1 * 4 + 2 + 1 + 1 + 35 * args.maxEntries.toNumber()
),
space:
8 +
32 * 4 +
8 * 9 +
1 * 4 +
2 +
1 +
1 +
35 * args.maxEntries.toNumber(),
}),
SystemProgram.createAccount({
fromPubkey: wallet.publicKey,
newAccountPubkey: fixedGameKeypair.publicKey,
programId: gameProgram.programId,
lamports: await connection.getMinimumBalanceForRentExemption(
8 + 32 + 4 + 35 * args.maxEntries.toNumber()
),
space: 8 + 32 + 4 + 35 * args.maxEntries.toNumber(),
}),
])
.signers([gameKeypair, fixedGameKeypair])
.rpc();
This code works for me on devnet, but failing on mainnet! The log is really vague to me and couldn't search it anywhere, my biggest guess is that the owner of the associated token account is a PDA (not on curve). Please help, thanks for your time!