|
2 | 2 |
|
3 | 3 | A canister demonstrating how to receive ICP tokens by generating account identifiers and checking balances on the ICP ledger. |
4 | 4 |
|
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. |
0 commit comments