This document serves as a comprehensive walkthrough to deploy and interact with the ICSI canister on the Internet Computer mainnet and local network.
-
Internet Identity (II): Acquire your Internet Identity via Internet Identity. It's recommended to use a password manager like Bitwarden with Chrome extension for passkey activation.
-
NNS Login: Access the NNS Dapp and log in.
-
ICP Tokens: Top up at least 2.0 ICP tokens to your NNS-II address. Navigate to
Tokens > Internet Computer
in the NNS Dapp. -
DFX CLI: Install the DFINITY Canister SDK (DFX) on your system. Follow the guide at Installing tools | Internet Computer.
-
Git and Rust: Ensure you have Git and Rust installed on your system.
Create a new identity locally using dfx
:
dfx identity new custodian_name
Verify and manage identities:
dfx identity whoami
dfx identity list
dfx identity use some_idname
Export the principal address to an environment variable:
export CUSTODIAN_PRINCIPAL=$(dfx identity get-principal)
- Create a new canister through the NNS Dashboard.
- Add cycles to the canister.
- Add the controller using the
custodian_principal
obtained earlier.
git clone [email protected]:garudaidr/icp-subaccount-indexer-prototype.git
cd icp-subaccount-indexer-prototype
Create or modify canister_ids.json
in the project root:
{
"icp_prototype_backend": {
"ic": "upy4y-myaaa-aaaaal-qjbxa-cai"
}
}
Replace the canister ID with the one from your NNS dashboard.
Sync the local wallet to the mainnet:
dfx identity --network ic deploy-wallet <canister_id>
Convert ICP to cycles:
dfx cycles convert 0.3 --network ic
Use the deploy.sh
script for deployment:
# Deploy to mainnet (IC network)
./deploy.sh --network ic
# Deploy to local network
./deploy.sh --network local
# For a clean local deployment
./deploy.sh --network local --clean
Alternatively, you can use the dfx command directly:
dfx deploy icp_prototype_backend --network ic --no-wallet --argument "(variant { Mainnet }, 15 : nat64, 10 : nat32, \"ryjl3-tyaaa-aaaaa-aaaba-cai\", \"$CUSTODIAN_PRINCIPAL\")"
Note: If you encounter issues with the wasm32-unknown-unknown
target, install it:
rustup target add wasm32-unknown-unknown
Export the Canister ID:
export CANISTER_ID=<your_canister_id>
Initialize the poller:
dfx canister --network ic call $CANISTER_ID set_interval '(1)'
Set the starting block to avoid querying from 0:
dfx canister --network ic call $CANISTER_ID set_next_block '(12110174)'
Verify the current block:
dfx canister --network ic call $CANISTER_ID get_next_block '()'
The test.sh
script provides a comprehensive test suite:
# Run tests with deployment
./test.sh --network local
# Run tests without deployment
./test.sh --network local --skip-deploy
The index.js
file offers an interactive CLI for canister interaction:
-
Interactive mode:
node index.js
-
CLI mode:
# Add a subaccount node index.js --cli add_subaccount # Set webhook URL node index.js --cli set_webhook_url https://example.com/webhook
Test methods using the format:
dfx canister --network ic call $CANISTER_ID <method_name> '<argument>'
Examples:
# Check canister status
dfx canister --network ic call $CANISTER_ID canister_status '()'
# Sweep funds
dfx canister --network ic call $CANISTER_ID sweep '()'
# Check balance
dfx ledger --network ic balance
# Transfer out (deduct 0.0001 for fee)
dfx ledger transfer --network ic --amount 0.5098 --memo 0 5c8aea1a5c6b871125c5b876688f2c28483a37314717750f2175156742fd08d8
dfx identity export <identity_name>
dfx identity import <identity_name> <pem_file>
List and switch identities:
dfx identity list
dfx identity use <some_id>
If the initial deployment doesn't set the principal ID or ledger ID correctly, modify the post_upgrade()
function in your Rust code:
async fn post_upgrade() {
let custodian_principal = "".to_string(); // fill this ""
let custodian_principal = Principal::from_text(&custodian_principal).expect("Invalid custodian principal");
CUSTODIAN_PRINCIPAL.with(|principal_ref| {
let stored_principal = StoredPrincipal::new(custodian_principal);
let _ = principal_ref.borrow_mut().set(stored_principal);
});
let ledger_principal = "ryjl3-tyaaa-aaaaa-aaaba-cai".to_string();
let principal = Principal::from_text(&ledger_principal).expect("Invalid ledger principal");
PRINCIPAL.with(|principal_ref| {
let stored_principal = StoredPrincipal::new(principal);
let _ = principal_ref.borrow_mut().set(stored_principal);
});
ic_cdk::println!("running post_upgrade...");
reconstruct_subaccounts();
reconstruct_network();
}
This comprehensive guide should help you deploy, test, and interact with your ICSI canister effectively.