1

I'm trying to interact with an smart contract to borrow SOL as a flash loan.

I'm getting this error:

Failed to send transaction: ClientError { request: Some(SendTransaction), 
kind: RpcError(RpcResponseError { code: -32002, 
message: "Transaction simulation failed: Error processing Instruction 0: custom program error: 0x65",
data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(0, Custom(101))),
logs: Some(["Program 1oanfPPN8r1i4UbugXHDxWMbWVJ5qLSN5qzNFZkz6Fg invoke [1]",
"Program log: AnchorError occurred. Error Code: InstructionFallbackNotFound. Error Number: 101. Error Message: Fallback functions are not supported.",
"Program 1oanfPPN8r1i4UbugXHDxWMbWVJ5qLSN5qzNFZkz6Fg consumed 3718 of 200000 compute units",
"Program 1oanfPPN8r1i4UbugXHDxWMbWVJ5qLSN5qzNFZkz6Fg failed: custom program error: 0x65"]),
accounts: None, units_consumed: Some(3718) }) }) }

I think I'm troubling a bit with Instruction_Data as Accounts are given as the IDL provides.

Here is my code:

#[derive(BorshSerialize, BorshDeserialize)]
struct BorrowInstructionData {
instruction: u8,
amount: u64,
}

fn main() {
let rpc_url = "https://api.mainnet-beta.solana.com";

let rpc_client = RpcClient::new_with_commitment(rpc_url.to_string(), CommitmentConfig::processed());

let payer = Keypair::from_base58_string("Private key");
let payer_pubkey = payer.pubkey();

let token_program = Pubkey::from_str("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA").unwrap();

let system_program = Pubkey::from_str("Sysvar1nstructions1111111111111111111111111").unwrap();

let wsol_pubkey = Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap();

let ass_acc = get_associated_token_address(&payer.pubkey(), &Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap());

let program_id = Pubkey::from_str("1oanfPPN8r1i4UbugXHDxWMbWVJ5qLSN5qzNFZkz6Fg").unwrap();

let ass_acc_from = get_associated_token_address(&Pubkey::from_str("7vakD43rUC9QkmSp6GTG3FrPRKp2ebz7yTS1a9DAZJUb").unwrap(), &Pubkey::from_str("So11111111111111111111111111111111111111112").unwrap());

let pool_auth = Pubkey::from_str("7vakD43rUC9QkmSp6GTG3FrPRKp2ebz7yTS1a9DAZJUb").unwrap();

let amount: u64 = 100000; 

let instruction_data = BorrowInstructionData {
    instruction: 3u8,
    amount,
};

let data_ix = instruction_data.try_to_vec().unwrap();

let borrow_ix = Instruction {
    program_id,
    accounts: vec![
        AccountMeta::new(payer_pubkey, true),  
        AccountMeta::new(ass_acc_from, false),  
        AccountMeta::new(ass_acc, false),  
        AccountMeta::new_readonly(pool_auth, false), 
        AccountMeta::new_readonly(system_program, false), 
        AccountMeta::new_readonly(token_program, false), 
    ],
    data: data_ix, 
};

let instructions = vec![borrow_ix];

let recent_blockhash = match rpc_client.get_latest_blockhash() {
    Ok(blockhash) => blockhash,
    Err(e) => {
        eprintln!("Failed to get latest blockhash: {}", e);
        return;
    }
};

let transaction = Transaction::new_signed_with_payer(
    &instructions,
    Some(&payer_pubkey),
    &[&payer],
    recent_blockhash,
);

match rpc_client.send_and_confirm_transaction(&transaction) {
    Ok(signature) => println!("Transaction signature: {:?}", signature),
    Err(e) => println!("Failed to send transaction: {:?}", e),
}

}

Thanks

2
  • what program is this? do you have access to the code?
    – Jimii
    Commented May 20 at 19:05
  • Hi Jimii, program is solscan.io/account/… Its deployed by another user so I dont have access to the code but to the IDL, thats why in my code the instruction from instruction_data is 3u8
    – Culebrilio
    Commented May 20 at 19:37

1 Answer 1

2

The error InstructionFallbackNotFound is usually thrown by Anchor when the on-chain program cannot find the correct function to be called on the on-chain program. For Anchor the entrypoint method is generated by Anchor and it checks what function to call. The decision what function is to be called is made by Discriminator. Those are first 8 bytes provided in instruction data (see https://solana.stackexchange.com/a/4996/1386, the Discriminator is derived from the struct name that's serialized at the call (in your case BorrowInstructionData => let data_ix = instruction_data.try_to_vec().unwrap()).

In other words I bet you define wrong instruction data that the Anchor program is not capable to decrypt and find the function to invoke for your call.

I believe the instruction: 3u8, is not the correct data input as the Anchor discriminator consists of 8 bytes.

As you shared the program you work with (1oanfPPN8r1i4UbugXHDxWMbWVJ5qLSN5qzNFZkz6Fg) then I recommend to check the security.txt tab https://solscan.io/account/1oanfPPN8r1i4UbugXHDxWMbWVJ5qLSN5qzNFZkz6Fg#programSecurity where you can sometimes find the link to source code of the program. Here it's https://github.com/moshthepitt/flash-loan-mastery/blob/master/programs/flash-loan-mastery/src/lib.rs

Here the discriminator is defined in code that could help possibly https://github.com/moshthepitt/flash-loan-mastery/blob/master/programs/flash-loan-mastery/src/lib.rs#L213C10-L214

Or, as you probably(!) have the sources you could maybe link that repository to your code and use the anchor-client https://docs.rs/anchor-client/latest/anchor_client/ to create the instruction data.

1
  • 1
    Thank you so much for your dedication, I was able to make it work. Thanks.
    – Culebrilio
    Commented May 21 at 19:27

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.