Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/receiving-icp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: receiving_icp
Comment thread
marc0olo marked this conversation as resolved.

on:
push:
branches: [master]
pull_request:
paths:
- rust/receiving-icp/**
- .github/workflows/receiving-icp.yml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rust-receiving_icp:
runs-on: ubuntu-24.04
container: ghcr.io/dfinity/icp-dev-env-rust:1.0.1
env:
ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Deploy and test
working-directory: rust/receiving-icp
run: |
icp network start -d
icp deploy
bash test.sh
Comment thread
marc0olo marked this conversation as resolved.
139 changes: 108 additions & 31 deletions rust/receiving-icp/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions rust/receiving-icp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
[package]
name = "receiving-icp"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
candid = "0.10.19"
ic-cdk = "0.18.7"
ic-ledger-types = "0.15.0"
[workspace]
members = ["backend"]
resolver = "2"
53 changes: 52 additions & 1 deletion rust/receiving-icp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,55 @@

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

This canister can be deployed on [ICP Ninja](https://icp.ninja/projects/receive-icp) for quick testing and demonstration.
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.

## Environment configuration

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")`:

| Environment | Ledger | Canister ID |
|---|---|---|
| `local` | ICP ledger (pre-deployed by icp-cli) | `ryjl3-tyaaa-aaaaa-aaaba-cai` |
| `staging` | TESTICP ledger | `xafvr-biaaa-aaaai-aql5q-cai` |
| `production` | ICP ledger (mainnet) | `ryjl3-tyaaa-aaaaa-aaaba-cai` |

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.

## Build and deploy from the command line

### Prerequisites

- Node.js
- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm`

### Install

```bash
git clone https://github.com/dfinity/examples
cd examples/rust/receiving-icp
```

### Deploy and test locally

```bash
icp network start -d
icp deploy
bash test.sh
icp network stop
```

`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.

### Deploy to staging or production

```bash
# Staging — targets the TESTICP ledger
icp deploy --environment staging

# Production — targets the mainnet ICP ledger
icp deploy --environment production
```

## Security considerations and best practices

Refer to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for information on security and best practices for your ICP app.
13 changes: 13 additions & 0 deletions rust/receiving-icp/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "backend"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]
path = "lib.rs"

[dependencies]
candid = "0.10"
ic-cdk = "0.20"
ic-ledger-types = "0.16"
Loading
Loading