Tutorials
Token Factory

Token Factory Tutorial

The tokenfactory module enables any account to create new tokens with a unique identifier based on the creator's address. Each account can generate multiple tokens by specifying distinct denoms. The token creator is granted "admin" privileges, allowing them to mint, burn, and transfer their token.

These tokens are named factory/{CREATOR_ADDRESS}/{DENOM} and come with a range of native functionalities.

Requirements

To create a token on the devnet, ensure you have the following setup:

  • The seid CLI
  • A wallet with SEI tokens on devnet
You can obtain devnet tokens from one of the faucets listed here.

Creating a Denom

seid tx tokenfactory create-denom $DENOM --from=$ACCOUNT --chain-id=arctic-1 --node=https://rpc.arctic-1.seinetwork.io/ --broadcast-mode=block --fees=20000usei

This command creates a new coin with the format factory/{ACCOUNT}/{DENOM}. Replace $DENOM with your desired denom name and $ACCOUNT with your account name. The account specified here will be the token admin.

💡

Simplify your tutorial experience by setting the $DENOM and $ACCOUNT variables in your terminal. This allows you to easily refer to these variables throughout the tutorial.

For instance, to set a denom called solid and use the account name of your choice, use the following commands:

DENOM=solid
ACCOUNT=your_account_name

Replace your_account_name with the actual name of your account. Once set, you can refer to these values throughout the session using $DENOM and $ACCOUNT.

Understanding Command Line Arguments

When executing commands in this tutorial, you'll encounter several arguments. Here's a brief overview of what each means:

  • --chain-id arctic-1: This specifies the network where the command will be executed. In this case, arctic-1 is the identifier for the Sei devnet.
  • --node https://rpc.arctic-1.seinetwork.io/ : This points to the RPC URL of the node you are interacting with.
  • --broadcast-mode block: This determines how your transaction is broadcasted to the network. The block mode means the transaction will wait to be included in a block before returning a response. This is a safer option as it confirms your transaction is processed.
  • --fees 20000usei: This is used to specify the transaction fee.

Understanding these arguments will help you execute the commands more confidently and customize them as needed for different scenarios.

For detailed descriptions of these arguments, use seid help in the CLI.

Updating Token Metadata

When creating a token, it is important to specify details regarding the denom amounts and aliases so your token can be correctly parsed on wallets and explorers.

1. Create Token Metadata file

Create a token metadata json file. The file below is an example metadata file for the Sei token.

{
	"name": "sei",
	"description": "The native token of Sei.",
	"symbol": "SEI",
	"denom_units": [
		{
			"denom": "usei",
			"exponent": 0,
			"aliases": ["microsei"]
		},
		{
			"denom": "msei",
			"exponent": 3,
			"aliases": ["millisei"]
		},
		{
			"denom": "sei",
			"exponent": 6
		}
	],
	"base": "usei",
	"display": "sei"
}

Example for token factory denom:

{
    "name": "factory/{ACCOUNT}/{DENOM}",
    "description": "A token created using the Token Factory module.",
    "symbol": "factory/{ACCOUNT}/{DENOM}",
    "denom_units": [
        {
            "denom": "factory/{ACCOUNT}/{DENOM}",
            "exponent": 0,
            "aliases": ["microdenom"]
        },
        {
            "denom": "mdenom",
            "exponent": 3
        },
        {
            "denom": "{DENOM}",
            "exponent": 6
        }
    ],
    "base": "factory/{ACCOUNT}/{DENOM}",
    "display": "{DENOM}"
}

The base field denotes the smallest denom that this token can be represented in. Note that if you intend to create a pointer contract, the denom_units with the largest exponent will be used as the display denom. (sei in this case).

2. Set token metadata using seid

seid tx tokenfactory set-denom-metadata $METADATA_FILE --fees 20000usei -b block -y --from $ADDR

Replace $METADATA_FILE with the path to your metadata file created in step 1. and $ADDR with the address of the token admin.

Minting Tokens

seid tx tokenfactory mint $AMOUNT --from=$ACCOUNT --chain-id=arctic-1 --node=https://rpc.arctic-1.seinetwork.io/ --broadcast-mode=block --fees=20000usei

This command will create (mint) a specific $AMOUNT of your new token. Replace $AMOUNT with the number of tokens you want to mint, followed by the token denom generated from the previous command.

💡

For instance, if you would like to mint 1M tokens, you should input 1000000factory/{ACCOUNT}/{DENOM} as amount or you could set a new variable for the amount:

AMOUNT=1000000factory/${ACCOUNT}/${DENOM}

To verify that the tokens have been minted, query the balance of your account:

seid query bank balances $ACCOUNT --chain-id=arctic-1 --node=https://rpc.arctic-1.seinetwork.io/

Burning Tokens

seid tx tokenfactory burn $AMOUNT --from=$ACCOUNT --chain-id=arctic-1 --node=https://rpc.arctic-1.seinetwork.io/ --broadcast-mode=block --fees=20000usei

This command allows you to burn a specific amount of your tokens, reducing the total supply. To use it, replace $AMOUNT with the number of tokens you wish to destroy.

💡

For instance, to burn 100 tokens, you should input 100factory/{ACCOUNT}/{DENOM}. Ensure that you substitute {ACCOUNT} and {DENOM} with your actual account address and token denomination, respectively. You can also update the variable:

AMOUNT=100factory/${ACCOUNT}/${DENOM}

Only the token admin has permission to mint and burn tokens. If necessary, you can reassign these privileges by using the change-admin command to designate a new admin.

Create Pointer Contract

To enable seamless use of this token in EVM environments, we can create a pointer contract. This process results in an ERC20 token that can be imported and used in EVM wallets and applications.

seid tx evm register-evm-pointer NATIVE factory/${ACCOUNT}/${DENOM} --from=$ACCOUNT --fees 20000usei --evm-rpc=https://evm-rpc.arctic-1.seinetwork.io/

Parameters

  • DENOM: The denomination of the token for which you want to create an ERC20 pointer. This should match the TokenFactory token you created.

Flags

  • --from: The Sei address from which the deployment transaction is sent. This address must have enough balance to cover transaction fees.
  • --evm-rpc: The endpoint URL for the EVM RPC interface of the Sei blockchain. This URL is used by the seid command to interact with the Sei EVM.

Executing this command creates an ERC20 token. This token is linked to the TokenFactory token, meaning any activities involving this ERC20 token will also reflect on the state of the TokenFactory token and vice versa.

Note that if you wish to specify denoms on your ERC20 tokens, you will need to set the token metadata for the base tokenfactory token. The denom with the largest exponent will be used.

To query the pointer contract address run the following command:

seid q evm pointer NATIVE factory/${ACCOUNT}/${DENOM} --node=https://rpc.arctic-1.seinetwork.io/

Which will return the address of the pointer contract.

exists: true
pointer: 0xPointerContractAddress
version: 1

Now this pointer contract can be used in EVM environments to interact with your TokenFactory token.

Learn more about EVM interoperability and pointer contracts here.

Next Steps

🎉 Congrats on completing the Token Factory tutorial! You've learned how to create, mint, and burn tokens on Sei using the tokenfactory module.

💡
Smart contracts can also create TokenFactory denoms and act as token admins, allowing for more complex and automated token management strategies.

For more advanced features and detailed insights, please refer to the Token Factory module documentation (opens in a new tab).