DIP20: 互联网计算机token铸造技术标准

DIP20: A fungible token standard for the DFINITY Internet Computer

DIP20 - Introduction

Token standards are essential for the Internet Computer ecosystem, especially for the decentralized finance ecosystem (DeFi) system. In this token interface, we implemented an ERC-20 style token standard in both Motoko and Rust, the standard is named DIP20.   通证标准对于互联网计算机生态系统,尤其是去中心化金融生态系统(DeFi)至关重要。 在此代币接口中,我们在 Motoko 和 Rust 中实现了 ERC-20 风格的代币标准,该标准名为 DIP20。

This standard allows for a common and familiar interface that not only provides a quick entry point for existing blockchain developers, but future interoperability options between the Internet Computer and Ethereum, through the process of sustaining the same shared interfaces.   该标准允许使用通用且熟悉的接口,该接口不仅为现有区块链开发人员提供了快速切入点,而且通过维持相同的共享接口的过程,为互联网计算机和以太坊之间的未来互操作性选项提供了选择。

You can find the interface descriptions in the specification file.

Specification

1. Data Structures

  1. Metadata: basic token information

    type Metadata = {
        logo : Text; // base64 encoded logo or logo url
        name : Text; // token name
        symbol : Text; // token symbol
        decimals : Nat8; // token decimal
        totalSupply : Nat; // token total supply
        owner : Principal; // token owner
        fee : Nat; // fee for update calls
    }
  2. TxReceipt: receipt for update calls, contains the transaction index or an error message

    public type TxReceipt = {
        #Ok: Nat;
        #Err: {
             #InsufficientAllowance;
             #InsufficientBalance;
             #ErrorOperationStyle;
             #Unauthorized;
             #LedgerTrap;
             #ErrorTo;
             #Other: Text;
             #BlockUsed;
             #AmountTooSmall;
        };
    };
    
    when the Transaction status is #failed, an error should be returned instead of a transaction id
  3. TxRecord: history transaction record

    public type Operation = {
        #approve;
        #mint;
        #transfer;
        #transferFrom;
    };
    public type TransactionStatus = {
        #succeeded;
        #failed;
    };
    public type TxRecord = {
        caller: ?Principal;
        op: Operation; // operation type
        index: Nat; // transaction index
        from: Principal;
        to: Principal;
        amount: Nat;
        fee: Nat;
        timestamp: Time.Time;
        status: TransactionStatus;
    };

    caller in TxRecord is optional and only need to be non-empty for transferFrom calls

This branch contains code of several other token canister templates.

Development

You need the latest DFINITY Canister SDK to be able to build and deploy a token canister:

sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)"

Navigate to a the sub directory and start a local development network:

cd motoko
dfx start --background

Create canisters:

dfx canister create --all

Install code for token canister:

dfx build

dfx canister install token --argument="(\"<LOGO>\", \"<NAME>\", \"<SYMBOL>\", <DECIMALS>, <TOTAL_SUPPLY>, <YOUR_PRINCIPAL_ID>, <FEE>)"
e.g.:
dfx canister install token --argument="(\"data:image/jpeg;base64,...\", \"DFinance Coin\", \"DFC\", 8, 10000000000000000, principal \"4qehi-lqyo6-afz4c-hwqwo-lubfi-4evgk-5vrn5-rldx2-lheha-xs7a4-gae\", 10000)"

Refer to demo.sh in the corresponding sub directory for more details.

DIP20: 互联网计算机token铸造技术标准
arkMeta Crypto Network Limited, arkSong 2023年10月23日
标签
登录 留下评论

互联网计算机环境下的身份技术规范
The Internet Identity Specification