Skip to content
forked from NatLabs/icrc1

A full implementation of the ICRC-1 fungible token standard in stable memory

License

Notifications You must be signed in to change notification settings

NatLabs/icrc-token

 
 

Repository files navigation

ICRC-1 Implementation

This repo contains the implementation of the ICRC-1 token standard.

References and other implementations

Documentation

Getting Started

  • Expose the ICRC-1 token functions from your canister

    • Import the icrc1 lib and expose them in an actor class.

      Take a look at the examples

  • Launch the basic token with all the standard functions for ICRC-1

    • Install the mops package manager
    • Replace the values enclosed in < > with your desired values and run in the terminal
      git clone https://github.com/NatLabs/icrc1
      cd icrc1
      mops install
      dfx start --background --clean
    
      dfx deploy icrc1 --argument '( record {                     
          name = "<Insert Token Name>";                         
          symbol = "<Insert Symbol>";                           
          decimals = 6;                                           
          fee = 1_000_000;                                        
          max_supply = 1_000_000_000_000;                         
          initial_balances = vec {                                
              record {                                            
                  record {                                        
                      owner = principal "<Insert Principal>";   
                      subaccount = null;                          
                  };                                              
                  100_000_000                                 
              }                                                   
          };                                                      
          min_burn_amount = 10_000;                         
          minting_account = null;                                 
          advanced_settings = null;                               
      })'
  • Create a token dynamically from a canister

        import Nat8 "mo:base/Nat8";
        import Token "mo:icrc1/ICRC1/Canisters/Token";
    
        actor{
            let decimals = 8; // replace with your chosen number of decimals
    
            func add_decimals(n: Nat): Nat{
                n * 10 ** decimals
            };
    
            let pre_mint_account = {
                owner = Principal.fromText("<Insert Principal>");
                subaccount = null;
            };
    
            let token_canister = Token.Token({
                name = "<Insert Token Name>";
                symbol = "<Insert Token Symbol>";
                decimals = Nat8.fromNat(decimals);
                fee = add_decimals(1);
                max_supply = add_decimals(1_000_000);
    
                // pre-mint 100,000 tokens for the account
                initial_balances = [(pre_mint_account, add_decimals(100_000))]; 
    
                min_burn_amount = add_decimals(10);
                minting_account = null; // defaults to the canister id of the caller
                advanced_settings = null; 
            });
        }

The fields for the advanced_settings record are documented here

Tests

Internal Tests

  • Download and Install vessel
  • Run make test
  • Run make actor-test
  • Install Rust and Cargo via rustup
    curl https://sh.rustup.rs -sSf | sh
  • Then run the ref-test command
    make ref-test

Funding

This library was initially incentivized by ICDevs. You can view more about the bounty on the forum or website. The bounty was funded by The ICDevs.org community and the DFINITY Foundation and the award was paid to @NatLabs. If you use this library and gain value from it, please consider a donation to ICDevs.

About

A full implementation of the ICRC-1 fungible token standard in stable memory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Motoko 97.9%
  • Dhall 1.2%
  • Makefile 0.9%