0
  let fee_pubkey_str = "auth8dV96CVJrsFxAdDM13eo1fFq9vE27C2EJ2yezJw"; 

    let fee_pubkey = Pubkey::from_str(fee_pubkey_str).unwrap();

    let transfer_to_fee = solana_program::system_instruction::transfer(
        &ctx.accounts.player.key(),
        &fee_pubkey,
        ctx.accounts.game_match.commission_amount,
    );
    solana_program::program::invoke(
        &transfer_to_fee,
        &[
            ctx.accounts.player.to_account_info(),
            // Add fee account_info()
            ctx.accounts.system_program.to_account_info(),
        ],
    )?;

output: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing

How can I add fee account info? All I want to do is to provide a fee flow to the public wallet, which I define as hardcode.

Thank you guys!

2 Answers 2

3

You need to pass in the account you want to transfer the funds to in your Accounts struct and use that in the transfer instruction.

Using the transfer instruction from anchor would look like this

    use anchor_lang::system_program::Transfer

    let cpi_accounts = Transfer {
        from,
        to,
    };
    let cpi_program = system_program.to_account_info();
    let cpi_context = CpiContext::new(cpi_program, cpi_accounts);
    system_program::transfer(cpi_context, fees).expect("Insufficient Funds");

Becuase of how Solana processes instructions, you need to tell it beforehand the accounts it will interact with and as such passing in a public key is not currently supported.

1

The account is missing since you've only provided the address within the instruction logic. You'll need to include the fee_pubkey as one of the accounts required by the instruction instead of hardcoding the address.

Here is an example you can reference for how to create an instruction for a SOL transfer.

https://github.com/solana-developers/program-examples/blob/main/basics/transfer-sol/anchor/programs/transfer-sol/src/lib.rs

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.