Crates.io | ic-evm-sign |
lib.rs | ic-evm-sign |
version | 0.1.3 |
source | src |
created_at | 2022-12-05 15:55:53.191556 |
updated_at | 2022-12-21 17:11:07.466399 |
description | This library enables Internet Computer canisters to sign transactions for EVM-compatible blockchains |
homepage | |
repository | |
max_upload_size | |
id | 730440 |
size | 59,572 |
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
use ic_evm_sign;
#[update]
async fn create_address() -> Result<String, String> {
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:
dfx canister call ${canister_name} create_address
Sign an EVM-compatible transaction from a canister
use ic_evm_sign;
#[update]
async fn sign_tx(hex_raw_tx: Vec<u8>) -> Result<String, String> {
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:
dfx canister call ${canister_name} sign_tx '(vec {${hex_raw_tx}}: vec nat8)'
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:
ic_evm_sign::sign_transaction(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:
ic_evm_sign::sign_transaction(hex_raw_tx, chain_id, principal_id)
Find transaction types at: https://github.com/ethereum/execution-specs
git clone
cargo test
npm i
in e2e/tests
make e2e-test