This library enables Internet Computer canisters to sign transactions for EVM-compatible blockchains.
This is a two-part process:
There an example project at ic-evm-sign-starter.
Supported Tx Types: Legacy, EIP1559, EIP2930
You can get start quickly with ic-evm-sign-starter.
Run cargo add ic-evm-sign
in your project
Create a new EVM-compatible address from a canister
```rust use icevmsign;
async fn create_address() -> Result
let principal_id = ic_cdk::caller();
let response = ic_evm::create_address(principal_id).await
.map_err(|e| format!("Failed to create address {}", e))
.unwrap();
Ok(response.address)
} ```
Test locally with:
sh
dfx canister call ${canister_name} create_address
Sign an EVM-compatible transaction from a canister
```rust use icevmsign;
async fn signtx(hexraw_tx: Vec
let chain_id = 1;
let principal_id = ic_cdk::caller();
let response = ic_evm_sign::sign_transaction(hex_raw_tx, chain_id, principal_id).await
.map_err(|e| format!("Failed to sign transaction {}", e))
.unwrap();
Ok(response.sign_tx)
} ```
Test it locally with:
sh
dfx canister call ${canister_name} sign_tx '(vec {${hex_raw_tx}}: vec nat8)'
sh
dfx canister call ${canister_name} sign_tx '(vec {236; 128; 133; 5; 66; 135; 40; 189; 130; 117; 48; 148; 112; 153; 121; 112; 197; 24; 18; 220; 58; 1; 12; 125; 1; 181; 14; 13; 23; 220; 121; 200; 136; 13; 224; 182; 179; 167; 100; 0; 0; 0; 128; 128; 128}: vec nat8)'
For transaction hex:
0xec808505428728bd8275309470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000000808080
Use a different EVM-compatible blockchain using chain_id
in:
rust
ic_evm_sign::sign(hex_raw_tx, chain_id, principal_id)
Find chain ids at: https://chainlist.org
You can sign different transaction types hex by passing their corresponding hex using hex_raw_tx
in:
rust
ic_evm_sign::sign(hex_raw_tx, chain_id, principal_id)
Find transaction types at: https://github.com/ethereum/execution-specs
git clone
cargo test
npm start
in dev/local-node
(terminal 1) - Requires npm i
dfx start
(terminal 2)dfx deploy
npm start
(terminal 3) in dev/frontend
- Requires npm i