Skip to content

Commit a4de4dd

Browse files
authored
chore: migrate rust/receiving-icp to icp-cli (#1394)
1 parent 11f90e8 commit a4de4dd

11 files changed

Lines changed: 314 additions & 78 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: receiving_icp
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
paths:
8+
- rust/receiving-icp/**
9+
- .github/workflows/receiving-icp.yml
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
rust-receiving_icp:
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/receiving-icp
25+
run: |
26+
icp network start -d
27+
icp deploy
28+
bash test.sh

rust/receiving-icp/Cargo.lock

Lines changed: 108 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/receiving-icp/Cargo.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
[package]
2-
name = "receiving-icp"
3-
version = "0.1.0"
4-
edition = "2021"
5-
6-
[lib]
7-
crate-type = ["cdylib"]
8-
9-
[dependencies]
10-
candid = "0.10.19"
11-
ic-cdk = "0.18.7"
12-
ic-ledger-types = "0.15.0"
1+
[workspace]
2+
members = ["backend"]
3+
resolver = "2"

rust/receiving-icp/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,55 @@
22

33
A canister demonstrating how to receive ICP tokens by generating account identifiers and checking balances on the ICP ledger.
44

5-
This canister can be deployed on [ICP Ninja](https://icp.ninja/projects/receive-icp) for quick testing and demonstration.
5+
The canister exposes methods to compute account identifiers (including subaccounts based on arbitrary 128-bit upper/lower values) and to query balances from the ledger canister. This makes it easy to give each user or purpose a distinct deposit address while keeping all ICP under one canister's control.
6+
7+
## Environment configuration
8+
9+
The ICP ledger canister ID is configured via `icp.yaml` and read at runtime as a canister environment variable via `ic_cdk::api::env_var_value("ICP_LEDGER_CANISTER_ID")`:
10+
11+
| Environment | Ledger | Canister ID |
12+
|---|---|---|
13+
| `local` | ICP ledger (pre-deployed by icp-cli) | `ryjl3-tyaaa-aaaaa-aaaba-cai` |
14+
| `staging` | TESTICP ledger | `xafvr-biaaa-aaaai-aql5q-cai` |
15+
| `production` | ICP ledger (mainnet) | `ryjl3-tyaaa-aaaaa-aaaba-cai` |
16+
17+
The local environment uses the same principal as production because icp-cli's local network pre-deploys the ICP ledger at that well-known address. Staging uses the TESTICP ledger so you can test token flows without spending real ICP.
18+
19+
## Build and deploy from the command line
20+
21+
### Prerequisites
22+
23+
- Node.js
24+
- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm`
25+
26+
### Install
27+
28+
```bash
29+
git clone https://github.com/dfinity/examples
30+
cd examples/rust/receiving-icp
31+
```
32+
33+
### Deploy and test locally
34+
35+
```bash
36+
icp network start -d
37+
icp deploy
38+
bash test.sh
39+
icp network stop
40+
```
41+
42+
`bash test.sh` runs 7 tests: account identifier format, subaccount uniqueness, funding the main account and a specific subaccount via account ID hex, balance queries, and subaccount independence. Tests are delta-based and idempotent across re-runs.
43+
44+
### Deploy to staging or production
45+
46+
```bash
47+
# Staging — targets the TESTICP ledger
48+
icp deploy --environment staging
49+
50+
# Production — targets the mainnet ICP ledger
51+
icp deploy --environment production
52+
```
53+
54+
## Security considerations and best practices
55+
56+
Refer to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for information on security and best practices for your ICP app.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "backend"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
path = "lib.rs"
9+
10+
[dependencies]
11+
candid = "0.10"
12+
ic-cdk = "0.20"
13+
ic-ledger-types = "0.16"

0 commit comments

Comments
 (0)