Skip to main content
added 1334 characters in body
Source Link

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();

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();
Source Link

Test Validator SPL Associated Token Account IncorrectProgramId

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?