1

https://github.com/SushantChandla/test-mint-bug/blob/main/programs/mint-bug/tests/mint.rs

I am trying to create an associated token account please have a look at the github file. The error I get is Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: insufficient account keys for instruction which is weird as i am using the function provided in spl-associated-token-account crate and it should create instruction with all the required accounts.

async fn create_associated_token_account(
    context: &mut ProgramTestContext,
    account: &Pubkey,
    mint: &Pubkey,
    payer: &Keypair,
) -> transport::Result<Pubkey> {
    let associated_token_account = get_associated_token_address(account, mint);
    let associated_ix = spl_associated_token_account::instruction::create_associated_token_account(
        &payer.pubkey(),
        &account,
        &mint,
    );
    let associated_tx = get_signed_transaction(context, &[associated_ix], payer).await;

    context
        .banks_client
        .process_transaction(associated_tx)
        .await?;

    return Ok(associated_token_account);
}

Here are logs:

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/mint.rs (target/debug/deps/mint-b02ef8a2fffb7767)

running 1 test
[2022-08-14T17:00:14.371540000Z INFO  solana_program_test] "mint_bug" BPF program from /Users/sushantchandla/Projects/mint-bug/target/deploy/mint_bug.so, modified 1 minute, 74 ms, 62 µs and 704 ns ago
[2022-08-14T17:00:14.479628000Z DEBUG solana_runtime::message_processor::stable_log] Program 11111111111111111111111111111111 invoke [1]
[2022-08-14T17:00:14.479697000Z TRACE solana_runtime::system_instruction_processor] process_instruction: CreateAccount { lamports: 1461600, space: 82, owner: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA }
[2022-08-14T17:00:14.479729000Z TRACE solana_runtime::system_instruction_processor] keyed_accounts: [KeyedAccount { is_signer: false, is_writable: false, key: 11111111111111111111111111111111, account: RefCell { value: Account { lamports: 1, data.len: 14, owner: NativeLoader1111111111111111111111111111111, executable: true, rent_epoch: 0, data: 73797374656d5f70726f6772616d } } }, KeyedAccount { is_signer: true, is_writable: true, key: 7seLqAnajhJ5yFDgzFoBEt65ETYfZ99vWiuX3eDzu8Yg, account: RefCell { value: Account { lamports: 99999990000, data.len: 0, owner: 11111111111111111111111111111111, executable: false, rent_epoch: 0 } } }, KeyedAccount { is_signer: true, is_writable: true, key: BgGUR32WU9WJVwxdPKT4cfPnthg53TsikuoMWn8ZzBy8, account: RefCell { value: Account { lamports: 0, data.len: 0, owner: 11111111111111111111111111111111, executable: false, rent_epoch: 0 } } }]
[2022-08-14T17:00:14.479875000Z DEBUG solana_runtime::message_processor::stable_log] Program 11111111111111111111111111111111 success
[2022-08-14T17:00:14.497758000Z DEBUG solana_runtime::message_processor::stable_log] Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]
[2022-08-14T17:00:14.498167000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Instruction: InitializeMint
[2022-08-14T17:00:14.498666000Z DEBUG solana_rbpf::vm] BPF instructions executed (interp): 2253
[2022-08-14T17:00:14.498678000Z DEBUG solana_rbpf::vm] Max frame depth reached: 9
[2022-08-14T17:00:14.498686000Z DEBUG solana_runtime::message_processor::stable_log] Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2353 of 200000 compute units
[2022-08-14T17:00:14.498754000Z DEBUG solana_runtime::message_processor::stable_log] Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
[2022-08-14T17:00:14.515489000Z DEBUG solana_runtime::message_processor::stable_log] Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
[2022-08-14T17:00:14.516218000Z DEBUG solana_rbpf::vm] BPF instructions executed (interp): 1953
[2022-08-14T17:00:14.516231000Z DEBUG solana_rbpf::vm] Max frame depth reached: 4
[2022-08-14T17:00:14.516239000Z DEBUG solana_runtime::message_processor::stable_log] Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 1953 of 200000 compute units
[2022-08-14T17:00:14.516277000Z DEBUG solana_runtime::message_processor::stable_log] Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: insufficient account keys for instruction
test mint_tokens ... FAILED

failures:

---- mint_tokens stdout ----
thread 'mint_tokens' panicked at 'failed to create associated token account: TransactionError(InstructionError(0, NotEnoughAccountKeys))', programs/mint-bug/tests/mint.rs:84:6
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    mint_tokens

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.15s

3 Answers 3

2

I hit the same issue and found there is a difference in behaviour of solana validator versions. I worked against test validator in version 1.9.29 (developing on localhost). I was using the version of library spl-associated-token-account 1.1.1 that based on used import spl_associated_token_account::instruction creates the instruction meant for validator in version 1.10 and higher.

In fact, it does not matter of version of difference of spl-associated-token-account versions between 1.0.5 and 1.1.1. The both behaves the same in this regards (while 1.0.3 seems work differently).

See details in discussion here: https://github.com/solana-labs/solana-program-library/issues/2791

The difference is in account sysvar::rent::id() which seems to be required by old solana version (before 1.10).

If you import use spl_associated_token_account::instruction::create_associated_token_account then you need to work with solana version 1.10 (or higher) as the sysvar::rent::id() is not passed in the call. The new version does not require that account to be passed in. https://github.com/solana-labs/solana-program-library/blob/associated-token-account-v1.1.1/associated-token-account/program/src/instruction.rs#L76

If you import use spl_associated_token_account::create_associated_token_account then you can call against the solana version 1.9 as the rent::id is passed in the instruction call. https://github.com/solana-labs/solana-program-library/blob/associated-token-account-v1.1.1/associated-token-account/program/src/lib.rs#L101

1

You're missing the token_program_id

The create_associated_token_account takes four parameters.

pub fn create_associated_token_account(
    funding_address: &Pubkey,
    wallet_address: &Pubkey,
    token_mint_address: &Pubkey,
    token_program_id: &Pubkey,
) -> Instruction
2
0

I have the same problem. try add system_program_id & spl_token_id account:

        invoke(
        &spl_associated_token_account::instruction::create_associated_token_account(
            acc_funder_.key,
            acc_wallet_.key,
            acc_mint_.key,
        ),
        &[
            acc_funder_.clone(),
            acc_wallet_.clone(),
            acc_mint_.clone(),
            tacc_wallet_.clone(),
            acc_system_program_.clone(), // <-
            acc_spl_token_.clone(), // <-
        ]
    )?;

because create_associated_token_account wants also 2 implicit parameters

pub fn create_associated_token_account(
    funding_address: &Pubkey,
    wallet_address: &Pubkey,
    spl_token_mint_address: &Pubkey,
) -> Instruction {
    let associated_account_address = get_associated_token_address(wallet_address, spl_token_mint_address);

    let instruction_data = AssociatedTokenAccountInstruction::Create {};

Instruction {
    program_id: id(),
    accounts: vec![
        AccountMeta::new(*funding_address, true),
        AccountMeta::new(associated_account_address, false),
        AccountMeta::new_readonly(*wallet_address, false),
        AccountMeta::new_readonly(*spl_token_mint_address, false),
        AccountMeta::new_readonly(solana_program::system_program::id(), false), // <-
        AccountMeta::new_readonly(spl_token::id(), false), // <-
    ],
    data: instruction_data.try_to_vec().unwrap(),
    }
}
1
  • maybe you solved it in a different way, if so, write how.
    – Apigraf
    Commented Aug 29, 2022 at 14:10

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.