Skip to content

Commit d624165

Browse files
authored
chore: migrate rust/evm_block_explorer to icp-cli (#1435)
1 parent 9b1bbe2 commit d624165

17 files changed

Lines changed: 205 additions & 550 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: evm_block_explorer
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
paths:
8+
- rust/evm_block_explorer/**
9+
- .github/workflows/evm_block_explorer.yml
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
rust-evm_block_explorer:
17+
runs-on: ubuntu-24.04
18+
container: ghcr.io/dfinity/icp-dev-env-rust:1.0.1
19+
env:
20+
ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
steps:
22+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
23+
- name: Deploy and test
24+
working-directory: rust/evm_block_explorer
25+
run: |
26+
icp network start -d
27+
icp deploy
28+
bash test.sh

rust/evm_block_explorer/.devcontainer/devcontainer.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

rust/evm_block_explorer/BUILD.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

rust/evm_block_explorer/README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
## Overview
66

7-
The EVM Block Explorer example demonstrates how an ICP smart contract can obtain information directly from other blockchain networks. Using HTTPS outcalls, smart contracts on ICP can interact with other networks without needing to go through a third-party service such as a bridge or an oracle. Supported interactions with other chains include querying network data, signing transactions, and submitting transactions directly to other networks.
8-
In this example, you'll also see how to sign transactions with canister ECDSA or Schnorr signatures.
7+
The EVM Block Explorer example demonstrates how an ICP canister can fetch block data directly from Ethereum and other EVM-compatible chains. Using HTTPS outcalls via the [EVM RPC canister](https://github.com/dfinity/evm-rpc-canister), canisters on ICP can read on-chain data without a bridge or oracle. The same pattern applies to any EVM-compatible chain supported by the EVM RPC canister.
98

9+
<!--
1010
## Deploying from ICP Ninja
1111
12-
This example can be deployed directly from [ICP Ninja](https://icp.ninja), a browser-based IDE for ICP. To continue developing locally after deploying from ICP Ninja, see [BUILD.md](BUILD.md).
12+
This example can be deployed directly from [ICP Ninja](https://icp.ninja), a browser-based IDE for ICP.
1313
1414
[![Open in ICP Ninja](https://icp.ninja/assets/open.svg)](https://icp.ninja/i?g=https://github.com/dfinity/examples/rust/evm_block_explorer)
15-
16-
> **Note:** ICP Ninja currently uses `dfx` under the hood, which is why this example includes a `dfx.json` configuration file. `dfx` is the legacy CLI, being superseded by [icp-cli](https://cli.icp.build), which is what developers should use for local development.
15+
-->
1716

1817
## Build and deploy from the command line
1918

2019
### Prerequisites
2120

22-
- [x] Install [Node.js](https://nodejs.org/en/download/)
23-
- [x] Install [icp-cli](https://cli.icp.build): `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm`
21+
- [Node.js](https://nodejs.org/) v18+
22+
- [icp-cli](https://cli.internetcomputer.org/): `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm`
23+
- [Rust](https://www.rust-lang.org/tools/install) with `wasm32-unknown-unknown` target: `rustup target add wasm32-unknown-unknown`
2424

2525
### Install
2626

@@ -31,24 +31,29 @@ git clone https://github.com/dfinity/examples
3131
cd examples/rust/evm_block_explorer
3232
```
3333

34-
### Deployment
34+
### Deploy and test
3535

36-
Start the local network:
36+
Start the local network, deploy all canisters (including the local EVM RPC canister), and run the tests:
3737

3838
```bash
3939
icp network start -d
40+
icp deploy
41+
bash test.sh
42+
icp network stop
4043
```
4144

42-
Deploy the canisters:
45+
To start a frontend dev server with hot reload during frontend development:
4346

4447
```bash
45-
icp deploy
48+
npm run dev --prefix frontend
4649
```
4750

48-
Stop the local network when done:
51+
### Deploying on ICP mainnet
52+
53+
On mainnet, the `evm_rpc` canister is already deployed at `7hfb6-caaaa-aaaar-qadga-cai`. Deploy only the backend and frontend — icp-cli injects the correct canister ID via the `ic` environment configuration in `icp.yaml`:
4954

5055
```bash
51-
icp network stop
56+
icp deploy -e ic
5257
```
5358

5459
## Updating the Candid interface
@@ -58,10 +63,15 @@ The `backend/backend.did` file defines the backend canister's public interface.
5863
If you modify the backend's public API, rebuild the canister and regenerate the `.did` file:
5964

6065
```bash
61-
icp build backend
62-
candid-extractor target/wasm32-unknown-unknown/release/backend.wasm > backend/backend.did
66+
icp build backend && candid-extractor target/wasm32-unknown-unknown/release/backend.wasm > backend/backend.did
6367
```
6468

69+
## RPC providers and API keys
70+
71+
The example uses [PublicNode](https://ethereum-rpc.publicnode.com) by default — a free, no-registration provider that works out of the box locally and on mainnet. This is sufficient for getting started and automated testing.
72+
73+
For production deployments requiring premium providers (Alchemy, Ankr, BlockPi), refer to the [EVM RPC canister documentation](https://github.com/dfinity/evm-rpc-canister) for how to configure API keys. Once configured, change `RpcServices::EthMainnet(Some(vec![EthMainnetService::PublicNode]))` in `backend/src/lib.rs` to `RpcServices::EthMainnet(None)` to use all configured providers for better consensus.
74+
6575
## Security considerations and best practices
6676

67-
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://docs.internetcomputer.org/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.
77+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for developing on ICP. This example may not implement all the best practices.
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
[package]
22
name = "backend"
33
version = "0.1.0"
4-
edition = "2021"
5-
6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
4+
edition = "2024"
75

86
[lib]
97
crate-type = ["cdylib"]
10-
path = "lib.rs"
118

129
[dependencies]
1310
candid = "0.10.23"
14-
evm-rpc-canister-types = "5.0.1"
15-
hex = "0.4.3"
16-
ic-cdk = "0.17.2"
17-
ic0 = "1.0.1"
18-
sha2 = "0.10.8"
11+
evm_rpc_client = "0.4.0"
12+
evm_rpc_types = "3.1.1"
13+
ic-cdk = "0.20"
14+
ic-canister-runtime = "0.2.0"

rust/evm_block_explorer/backend/backend.did

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ type Block = record {
2121
gasUsed : nat;
2222
mixHash : text;
2323
};
24+
type Result = variant { Ok : Block; Err : text };
2425
service : {
25-
get_ecdsa_public_key : () -> (text);
26-
get_evm_block : (nat) -> (Block);
27-
get_schnorr_public_key : () -> (text);
28-
sign_message_with_ecdsa : (text) -> (text);
29-
sign_message_with_schnorr : (text) -> (text);
26+
get_evm_block : (nat) -> (Result);
3027
}

rust/evm_block_explorer/backend/lib.rs

Lines changed: 0 additions & 150 deletions
This file was deleted.

0 commit comments

Comments
 (0)