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