Understanding Token Contracts
At its core, a token contract is a smart contract that maintains a mapping of account addresses to their balances. These balances represent values defined by the contract creator—such as physical assets, monetary value, or reputation. The units of these balances are referred to as tokens.
Ethereum Token Contracts
When tokens are transferred between accounts, the contract updates the respective balances. You can track these transfers using an Ethereum block explorer.
Managing Token Supply
There are two primary ways to alter the total token supply:
- Minting: Creating new tokens (e.g., adding 100 tokens to an address).
- Burning: Reducing supply by destroying tokens. Sending tokens to an address without a private key (e.g., the zero address) renders them unusable, effectively achieving the same result as burning.
Definition of ERC-20 Token Contracts
An ERC-20 contract is identified by its address and total token supply, but it often includes additional details for clarity:
- Token Name: The full name of the token (e.g., "GoldToken"). Shorter names display better in wallets.
- Symbol: A shorthand identifier (e.g., "GLD"). Typically 3–4 characters long.
- Decimals: Defines the token’s divisibility, ranging from 0 (indivisible) to 18 (highly divisible). Decimals dictate how balances are displayed.
Examples:
- LicenseToken: Represents software licenses. Since fractional licenses are meaningless, decimals are set to 0.
- GoldToken: Represents physical gold. Each token equals 1 gram, but decimals are set to 3 to display balances in kilograms.
Rules for Setting Decimals:
- Indivisible assets: Use 0 decimals.
- Assets with natural divisions (e.g., grams of gold): Match the division unit.
- All other cases: Default to 18 decimals.
👉 Explore Ethereum tokens in depth
FAQs
Q: Why are decimals important in ERC-20 tokens?
A: Decimals determine how balances are displayed and ensure compatibility with Ethereum’s integer-only system.
Q: Can an ERC-20 token’s total supply change?
A: Yes, through minting (increasing supply) or burning (decreasing supply).
Q: What happens when tokens are sent to a zero address?
A: They become irrecoverable, effectively reducing the circulating supply.
Q: How do I choose a token symbol?
A: Opt for a short, unique identifier (3–4 characters) to avoid conflicts.
Q: Are ERC-20 tokens interchangeable?
A: Yes, as long as they adhere to the ERC-20 standard, enabling seamless integration with wallets and exchanges.