Skip to main content

Submitting transactions

Advanced
Ethereum
Tutorial

To submit transactions to the Ethereum network, first the transaction must be signed and formatted as an ETH transaction. Learn more about signing transactions.

Once you have your raw signed transaction, you can either programmatically submit the transaction, or use the EVM RPC canister's RPC method eth_sendRawTransaction.

Submitting transactions programmatically

Below is an example demonstrating how to submit a raw ETH transaction programmatically using Rust:

pub async fn send_raw_transaction(
tx: String,
rpc_services: RpcServices,
evm_rpc: EvmRpcCanister,
) -> SendRawTransactionStatus {
let cycles = 10_000_000_000;

match evm_rpc
.eth_send_raw_transaction(rpc_services, None, tx, cycles)
.await
{
Ok((res,)) => match res {
MultiSendRawTransactionResult::Consistent(status) => match status {
SendRawTransactionResult::Ok(status) => status,
SendRawTransactionResult::Err(e) => {
ic_cdk::trap(format!("Error: {:?}", e).as_str());
}
},
MultiSendRawTransactionResult::Inconsistent(_) => {
ic_cdk::trap("Status is inconsistent");
}
},
Err(e) => ic_cdk::trap(format!("Error: {:?}", e).as_str()),
}
}

View the full code example on GitHub.

Using the EVM RPC canister

To submit a raw transaction with the EVM RPC canister, make a call to the eth_sendRawTransaction method:

# Configuration
NETWORK=local
IDENTITY=default
CYCLES=1000000000
WALLET=$(dfx identity get-wallet)
RPC_SOURCE=EthMainnet
RPC_CONFIG=null

# Send a raw transaction
dfx canister call evm_rpc eth_sendRawTransaction "(variant {$RPC_SOURCE}, $RPC_CONFIG, \"0xf86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83\")" --with-cycles=$CYCLES --wallet=$WALLET

Learn more about the EVM RPC canister.

Resources