0

I'm running a Solana test validator, and I am using spl_associated_token_account::instruction::create_associated_token_account in a transaction to create an associated token account. The transaction creates correctly, and looks like

Transaction {
    signatures: [
        2Y4HFX523xCQqULmxFWCTK3NSUKHBTuHyTjyorDPX4ZDMq12MF1gRVaA7r7DLEZwtXPxdYqekTB7xp6vrwCQUJh7,
    ],
    message: Message {
        header: MessageHeader {
            num_required_signatures: 1,
            num_readonly_signed_accounts: 0,
            num_readonly_unsigned_accounts: 4,
        },
        account_keys: [
            5Xeu3dBDDuiugNvEvo6uN6VvWd37PUTgqFGJPJ32XkmP,
            GNR3TajYA7R3PU6q3SXnecHzgepm999G5TnMaTzKqcoD,
            11111111111111111111111111111111,
            TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA,
            82fDGLz84gDew1qxXVYDcTkEgb146niT6S76xHr1cbYR,
            ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL,
        ],
        recent_blockhash: E4wdTjBTgQh3cyWdX2Uxt97JVTNWr6fKkMyEh6pDKryq,
        instructions: [
            CompiledInstruction {
                program_id_index: 5,
                accounts: [
                    0,
                    1,
                    0,
                    4,
                    2,
                    3,
                ],
                data: [
                    0,
                ],
            },
        ],
    },
}

However, once I send the transaction to the test validator RPC endpoint, I get the following error:

ClientError { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 0: incorrect program id for instruction", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(0, IncorrectProgramId)), logs: Some(["Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", "Program log: Create", "Program 11111111111111111111111111111111 invoke [2]", "Program 11111111111111111111111111111111 success", "Program log: Initialize the associated token account", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", "Program log: Instruction: InitializeAccount3", "Program log: Error: IncorrectProgramId", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2392 of 184933 compute units", "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: incorrect program id for instruction", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 17459 of 200000 compute units", "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: incorrect program id for instruction"]), accounts: None, units_consumed: Some(0), return_data: None }) }) }

But this doesn't make any sense to me, since the program_id_index is 5, which corresponds to ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL, which is the valid program id for the spl_associated_token_account program.

Is there something I'm missing here?

Edit: context code is

let rpc_client = RpcClient::new(url.clone());
// create fake usdc token
let create_token_tx = Transaction::new_signed_with_payer(
    &[
        system_instruction::create_account(
            &alice_pubkey,
            &token_pubkey,
            rpc_client.get_minimum_balance_for_rent_exemption(
                Mint::LEN
            ).await.unwrap(),
            Mint::LEN as u64,
            &spl_token::id(),
        ),
        spl_token::instruction::initialize_mint(
            &spl_token::id(),
            &token_pubkey,
            &alice_pubkey,
            None,
            6,
        ).unwrap(),
    ],
    Some(&alice_pubkey),
    &[&alice, &TOKEN_KEYPAIR],
    rpc_client.get_latest_blockhash().await.unwrap()
);
// create fake usdc authority account
let create_account_tx = Transaction::new_signed_with_payer(
    &[
        spl_associated_token_account::instruction::create_associated_token_account(
            &alice_pubkey,
            &alice_pubkey,
            &token_pubkey,
        ),
    ],
    Some(&alice_pubkey),
    &[&alice],
    rpc_client.get_latest_blockhash().await.unwrap()
);
println!("{:#?}", create_account_tx);
// fails on the following instruction
rpc_client.send_transaction(&create_account_tx).await.unwrap();

1 Answer 1

1

This error is typically misleading. It is actually referring to the program ID of an account's owner. Check that all of your accounts are initialized to the expected program and passed in the correct order

4
  • i've looked at all the owners and it doesn't seem like there's anything wrong but obvs im wrong so the first account in account_keys is controlled by the system program which is expected so that's fine second account is a pda which i don't rlly know if there's an owner fifth account is spl fake-usdc mint address for testing, whose owner is the spl token program the rest of the accounts are programs, which are owned by the bpf loader and are prob fine right? is there anything u see wrong w this Commented Jul 28, 2022 at 17:34
  • no, but the fact that you were unable to verify the second account's owner makes it suspect. That PDA is the ATA to be created, it must be owned by the system program
    – trent.sol
    Commented Jul 28, 2022 at 18:22
  • well the spl_associated_token_account::instruction::create_associated_token_account creates the pda for me with spl_associated_token_account::get_associated_token_address so I don't ever interface with that myself. How could that be the problem Commented Jul 28, 2022 at 21:22
  • u can refer to the context code to see if there's anything wrong w that from first glance Commented Jul 28, 2022 at 21:35

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.