​ICRC-1 Ledger on a Local Replica

This guide will show you how to setup a local replica with a running Ledger that implements the ICRC-1 Fungible Token Standard.

​Step 0. Preparations

Before you start, make sure you have DFX. If you don’t have DFX installed, follow instructions on smartcontracts.org to install it.
While not necessary, you should work in empty directory
$ mkdir icrc1_ledger_test $ cd icrc1_ledger_test
Step 1. ​Download the Ledger
​The DFINITY Foundation publishes both the source code and the artefacts of its ICRC-1 Ledger. For this guide we are going to use the Ledger published with following commit of the Internet Computer repository
$ export IC_VERSION=1b619398c778efc62867a69ecb7b24209b4e076a
Download the ledger wasm and its candid file and unzip the ledger wasm
$ curl -o ic-icrc1-ledger.wasm.gz https://download.dfinity.systems/ic/${IC_VERSION}/canisters/ic-icrc1-ledger.wasm.gz $ curl -o icrc1.did https://raw.githubusercontent.com/dfinity/ic/${IC_VERSION}/rs/rosetta-api/icrc1/ledger/icrc1.did $ gunzip ic-icrc1-ledger.wasm.gz
The directory should now look like this
$ ls -sh1 * 1.2M ic-icrc1-ledger.wasm 4.0K icrc1.did

Step 2. Start the replica

​Create the file ​dfx.json​ with the following content
{ "canisters": { "icrc1-ledger": { "type": "custom", "wasm": "ic-icrc1-ledger.wasm", "candid": "icrc1.did" } } }
​Then start the replica
$ dfx start --background
​Before we can deploy the Ledger we need to get the principal that will be used as both minting account and controller of the archive canisters. For a local setup we are going to use the principal of the current identity.
Store the principal of the current identity inside an environment variable
$ export PRINCIPAL=$(dfx identity get-principal)
​Now you can deploy the Ledger
$ dfx deploy icrc1-ledger --argument "(record { token_symbol = \"TEX\"; token_name = \"Token example\"; minting_account = record { of = principal \"$PRINCIPAL\" }; transfer_fee = 10_000; metadata = vec {}; initial_balances = vec {}; archive_options = record { num_blocks_to_archive = 2000; trigger_threshold = 1000; controller_id = principal \"$PRINCIPAL\"; }; },)"

​Step 3. Mint some tokens

​It's finally time to mint some tokens! Let's mint 1_000_000 tokens to the principal akllx-q5q7v-sgdck-cjd7y-izqql-ck5rp-ee3c7-kzrea-k3fnf-pcuaw-pqe
$ dfx canister call icrc1-ledger icrc1_transfer '(record { to_principal=principal "akllx-q5q7v-sgdck-cjd7y-izqql-ck5rp-ee3c7-kzrea-k3fnf-pcuaw-pqe"; amount=1_000_000 },)'
and check the balance
$ dfx canister call icrc1-ledger icrc1_balance_of '(record { of=principal "akllx-q5q7v-sgdck-cjd7y-izqql-ck5rp-ee3c7-kzrea-k3fnf-pcuaw-pqe" },)' (1_000_000 : nat64)

Conclusions

​In this guide we have seen how to setup a local replica with an ICRC-1 Ledger installed and ready to be used.
​Feel free to drop feedback on the forum or on discord.
​Happy coding!
Made with Papyrs