I’ve deployed my canister locally for interacting with a smart contract deployed on sepolia. Do I have to deploy the canister to the mainnet for it to perform write access to the smart contract deployed on sepolia? Or it can perform the write functionality to the smart contract while deployed locally?
I’ve written to sepolia from local before. But you need to give your (local) canister some sepoliaETH, otherwise it can’t run a TX
How do I give my local canister some sepolia eth?
You transfer some ETH to your canister’s address. You can compute it like this
I have another error. Here is my canister’s URL: https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=gr5at-6yaaa-aaaal-qjfiq-cai
I am trying to call the function **call_increase_count** :
on the canister but it returns an error:
(variant {Err="Failed to send transaction: "Transaction failed: HttpOutcallError(InvalidHttpJsonRpcResponse { status: 500, body: \"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":341111,\\\"error\\\":{\\\"code\\\":-32603,\\\"message\\\":\\\"Internal server error\\\"}}\", parsingError: None })""})
This function calls a smart contract deployed on sepolia so that it can increase the count. Here’s the smart contract: Contract Address 0xAed5d7b083ad30ad6B50f698427aD4907845AAc3 | Etherscan
When I call the function **get_count** :
it works perfectly and returns the count:
(variant {Ok=1})
What can be the issue? Here’s my call_increase_count
code:
#[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?;
ic_cdk::println!("Canister address: {}", canister_address);
ic_cdk::println!("Nonce: {:?}", nonce);
let result = call_smart_contract(
CONTRACT_ADDRESS.to_string(),
&abi,
"increaseCount",
&[],
true,
Some(U64::from(11155111)), // Sepolia chain ID
Some(CONTRACT_ADDRESS.to_string()),
Some(U256::from(500000)), // Further increased gas limit
Some(U256::from(0)),
Some(nonce),
Some(U256::from(3_000_000_000u64)), // Further increased max priority fee
Some(U256::from(40_000_000_000u64)), // Further increased max fee
)
.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))
}
}
}
Here’s my get_nonce
function:
async fn get_nonce(address: &str) -> Result<U256, String> {
let rpc_services = RpcServices::EthSepolia(Some(vec![EthSepoliaService::Alchemy]));
let config = None;
let cycles = 10_000_000_000;
let params = GetTransactionCountArgs {
address: address.to_string(),
block: BlockTag::Latest,
};
match EvmRpcCanister::eth_get_transaction_count(rpc_services, config, params, cycles).await {
Ok((result,)) => match result {
MultiGetTransactionCountResult::Consistent(count_result) => match count_result {
GetTransactionCountResult::Ok(count) => Ok(U256::from(count)),
GetTransactionCountResult::Err(err) => Err(format!("RPC error: {:?}", err)),
},
MultiGetTransactionCountResult::Inconsistent(_) => Err("Inconsistent RPC results".to_string()),
},
Err(e) => Err(format!("Failed to get nonce: {:?}", e)),
}
}
The function is failing at this particular section for get_nonce
Here’s my Github code: