Skip to content

Demonstrate how to deploy and interact with ICRC-1 ledger.

License

Notifications You must be signed in to change notification settings

zhangwei983/icrc1-ledger-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample for ICRC-1 Ledger

Demonstrate how to deploy and interact with ICRC-1 ledger.

You can find the ledger Wasm and candid files under icrc1-ledger at ledger-suite-icrc-2024-11-28.

How to interact

Deploy the canisters

  1. Create an identity as the minter

    dfx new identity minter
    dfx identity get-principal --identity minter
  2. Replace the tdrdy-ztedg-ftfrj-mwmqh-wjl3j-pty4c-j63lp-xfvtt-7jxvp-4ialz-3ae principal with your minter principal in the dfx.json file. And you can modify the icrc1-ledger init arguments as well.

  3. Deploy the canisters

    dfx start --clean --background
    dfx deploy
  4. Set the ICRC-1 ledger

    dfx canister call icrc1-ledger-sample set_icrc1_ledger "(principal \"$(dfx canister id icrc1-ledger)\")"
    dfx canister call icrc1-ledger-sample get_icrc1_ledger

Mint tokens

  1. Mint tokens to an your default identity.

    dfx canister call icrc1-ledger icrc1_transfer "(record {to=record {owner=principal \"$(dfx identity get-principal)\"; subaccount=null}; fee=null; memo=null; from_subaccount=null; created_at_time=null; amount=10000})" --identity minter
    dfx canister call icrc1-ledger icrc1_balance_of "(record {owner=principal \"$(dfx identity get-principal)\"; subaccount=null})"
  2. Mint tokens to the icrc1-ledger-sample canister.

    dfx canister call icrc1-ledger icrc1_transfer "(record {to=record {owner=principal \"$(dfx canister id icrc1-ledger-sample)\"; subaccount=null}; fee=null; memo=null; from_subaccount=null; created_at_time=null; amount=10000})" --identity minter
    dfx canister call icrc1-ledger icrc1_balance_of "(record {owner=principal \"$(dfx canister id icrc1-ledger-sample)\"; subaccount=null})"
    

Transfer

  1. Tranfer the tokens from the icrc1-ledger-sample canister to your default identity.

    dfx canister call icrc1-ledger-sample transfer "(record {to=record {owner=principal \"$(dfx identity get-principal)\"; subaccount=null}; amount=100})"
  2. Verify the transfer

    dfx canister call icrc1-ledger icrc1_balance_of "(record {owner=principal \"$(dfx canister id icrc1-ledger-sample)\"; subaccount=null})"
    dfx canister call icrc1-ledger icrc1_balance_of "(record {owner=principal \"$(dfx identity get-principal)\"; subaccount=null})"

Transfer from

  1. Call the icrc2_approve to approve the icrc1-ledger-sample canister as the spender which can transfer on behalf of your default identity.

    dfx canister call icrc1-ledger icrc2_approve "(record {amount=100; spender=record {owner=principal \"$(dfx canister id icrc1-ledger-sample)\"}})"

    Note: The icrc_approve call on the ICRC-1 ledger takes transfer fee.

  2. Call the transfer_from of the icrc1-ledger-sample canister to transfer on behalf of your default identity.

    dfx canister call icrc1-ledger-sample transfer_from "(record {to=record {owner=principal \"$(dfx canister id icrc1-ledger-sample)\"; subaccount=null}; from=record {owner=principal \"$(dfx identity get-principal)\"; subaccount=null}; amount=99})"

    Note: The transfer_from call on the ICRC-1 ledger takes transfer fee.

  3. Verify the transfer

    dfx canister call icrc1-ledger icrc1_balance_of "(record {owner=principal \"$(dfx canister id icrc1-ledger-sample)\"; subaccount=null})"
    dfx canister call icrc1-ledger icrc1_balance_of "(record {owner=principal \"$(dfx identity get-principal)\"; subaccount=null})"

About

Demonstrate how to deploy and interact with ICRC-1 ledger.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages