ICP上でTokenの取り扱う規格として、EthereumにおけるERC-20のように『ICRC-1』があります。
Proposal | Description | did |
---|---|---|
ICRC-1 | Token Standard | ICRC-1.did |
ICRC-2 | Approve and Transfer From | ICRC-2.did |
ICP上でトークンを発行する方法について公式ドキュメントがあります。
https://internetcomputer.org/docs/current/developer-docs/integrations/icrc-1/deploy-new-token
試しにローカルPC上でつくってみることにします。
$ curl -o download_latest_icrc1_ledger.sh "https://raw.githubusercontent.com/dfinity/ic/master/rs/rosetta-api/scripts/download_latest_icrc1_ledger.sh"
※2023年9月19日時点で、Githubにコミットされているファイル名が「_ledger.sh」ではなく、「_leger.sh」となっているので注意
$ bash download_latest_icrc1_ledger.sh
Found artifacts for commit 21fa6190f619ae1179e3511092cd5644f61ceb3e. Downloading icrc1_ledger.did and icrc1_ledger.wasm.gz
※jqコマンドがインストールされている必要があります。
{
"canisters": {
"icrc1-ledger": {
"type": "custom",
"wasm": "icrc1-ledger.wasm",
"candid": "icrc1-ledger.did"
}
}
}
解説ページに載っているスクリプトをベースに、配備用スクリプトを用意します。
#!/bin/bash
# Change the variable to "ic" to deploy the ledger on the mainnet.
export NETWORK=local
# Change the variable to the principal that can mint and burn tokens.
export MINTER_PRINCIPAL=$(dfx identity get-principal)
# Change the variable to the principal that controls archive canisters.
export ARCHIVE_CONTROLLER=$(dfx identity get-principal)
export TOKEN_NAME="TM Token"
export TOKEN_SYMBOL=XTM
dfx deploy --network ${NETWORK} icrc1-ledger --argument "(variant { Init =
record {
token_name = \"${TOKEN_NAME}\";
token_symbol = \"${TOKEN_SYMBOL}\";
minting_account = record { owner = principal \"${MINTER_PRINCIPAL}\";};
initial_balances = vec {};
metadata = vec {};
transfer_fee = 10;
archive_options = record {
trigger_threshold = 2000;
num_blocks_to_archive = 1000;
controller_id = principal \"${ARCHIVE_CONTROLLER}\";
}
}})"
$ dfx start --background --clean
$ bash deploy_token.sh
$ dfx start --background --clean
Fungible Tokenの規格として、ICRC-1以外にも、IS20、DIP20、EXTといった規格があるようです。
https://www.blog.bitfinity.network/the-internet-computer-token-standards-a-comparison/