Hello @jennifertran, now I am getting another interesting error
When I call the function this is returned instead:
(variant {Ok="Increased count. Transaction hash: [String("InsufficientFunds")]"})
This is how my call_increase_count()
function looks like:
#[ic_cdk::update]
async fn call_increase_count() -> Result<String, String> {
let abi = get_abi();
let canister_address = get_canister_eth_address().await;
let nonce = get_nonce(&canister_address).await?;
let result = call_smart_contract(
CONTRACT_ADDRESS.to_string(),
&abi,
"increaseCount",
&[],
true,
Some(U256::from(11155111)), // Sepolia chain ID as U256
)
.await;
match result {
Ok(tx_hash) => {
ic_cdk::println!("Transaction sent successfully. Hash: {:?}", tx_hash);
Ok(format!("Increased count. Transaction hash: {:?}", tx_hash))
},
Err(e) => {
ic_cdk::println!("Error sending transaction: {:?}", e);
Err(format!("Failed to send transaction: {:?}", e))
}
}
}
This is how the section that sends the raw transaction in the call_smart_contract()
function looks like:
let value = value.unwrap_or_default();
let signed_tx = sign_transaction(
U64::from(CHAIN_ID as u64),
contract_address,
U256::from(GAS),
value,
next_id().await,
U256::from(MAX_PRIORITY_FEE_PER_GAS),
U256::from(MAX_FEE_PER_GAS),
data.to_vec(),
)
.await?;
let result = EVM_RPC
.eth_send_raw_transaction(
RpcServices::EthSepolia(Some(vec![
EthSepoliaService::PublicNode,
EthSepoliaService::BlockPi,
EthSepoliaService::Ankr,
])),
None::<evm_rpc_canister_types::RpcConfig>,
signed_tx.clone(),
10_000_000_000,
).await
.map_err(|e| format!("Failed to call eth_sendRawTransaction: {:?}", e))?;
match result {
(MultiSendRawTransactionResult::Consistent(send_result),) => {
match send_result {
SendRawTransactionResult::Ok(tx_status) => {
// Convert SendRawTransactionStatus to String
Ok(vec![Token::String(format!("{:?}", tx_status))])
},
SendRawTransactionResult::Err(err) => Err(format!("Transaction failed: {:?}", err)),
}
}
(MultiSendRawTransactionResult::Inconsistent(results),) => {
let errors: Vec<String> = results
.into_iter()
.map(|(service, send_result)| match send_result {
SendRawTransactionResult::Ok(tx_status) => format!("Success with status: {:?}", tx_status),
SendRawTransactionResult::Err(err) => format!("Service {:?} failed: {:?}", service, err),
})
.collect();
Err(format!("Inconsistent results: {:?}", errors))
}
}
Why am I getting the error "InsufficientFunds"
?