Skip to main content

Signing transactions

Advanced
Ethereum
Tutorial

Before a transaction can be sent to the Ethereum network, it must be signed and formatted into a raw ETH transaction. Transactions are signed with threshold ECDSA. For this example, the transaction standard EIP1559 will be used.

Build a transaction

First, a raw EIP1559 ETH transaction must be built containing the transaction's metadata, such as gas fee, sender, receiver, and transaction data. Below is a programmatic example of how to build a transaction using Rust:

packages/ic-evm-utils/src/eth_send_raw_transaction.rs
loading...

Format, hash, and sign a transaction

Ethereum EIP1559 transactions are first hashed with the Keccak256 algorithm and then signed using the private key. Below is an example written in Rust demonstrating how to format a raw ETH transaction, hash it using Keccak256 and sign the hash using threshold ECDSA. This code snippet accomplishes the following:

  • Formats the transaction.

  • Hashes the transaction using Keccak256.

  • Signs the Keccak hash.

  • Rebuilds the transaction using the VRS signature.

packages/ic-evm-utils/src/evm_signer.rs
loading...

Additional examples of signing transactions with threshold ECDSA can be found in the threshold ECDSA documentation.

Submit transaction

Now that your transaction is signed, it can be submitted to Ethereum to be executed.

Learn how to submit Ethereum transactions.