How Tokens Work on Solana
How tokens work on solana - explain for EVM developers
Let’s say you want to create a new type of fungible token, mint some to yourself, and then transfer some to your friend. What would you do?
- As a EVM developer, you have to deploy a new ERC20 smart contract.
- On Solana, you don’t need to create a new contract. There is a single token program (which was deployed by the Solana team) which responsible for creating, minting and transfering tokens.
- In order to create a new token, you send the
create
instruction to the token program. This creates a newmint account
. Each type of token is associated with exactly onemint account
which holds metadata about the token (likestotal supply
,decimals
,mint authority
- who allowed to mint,freeze authority
- who allowed to freeze account ).
- You’ve just created a new token but you don’t own any amount of this token yet. From
mint account
, you have to create atoken account
. Atoken account
stores how many tokens a particular user has, for a particular type of token.
Now, you have a
mint account
and atoken account
. Let’s mint some tokens. To mint, you just send themint
instruction to the token program, which tells the program how many tokens to mint and whom to mint them to. Only one user is allowed to mint a token of a particular type (themint authority
which mentioned above)To transfer tokens, no surprises, you send the
transfer
instruction to the token program, which tells it how many tokens to transfer and whom to transfer them. Note that the recipient must also own atoken account
for the type of token you’re transferring.
- What about NFTs? To create an NFT, you also use the same token program (what!!!), but these are some differences in how they are created and minted.
- As you know, an NFT is just a token that has one
total supply
and zerodecimal
. To create an NFT, you just need to create amint account
which has zerodecimal
. After that, you mint only one token of this NFT and disable future minting. This ensures there will only ever be one. - In practice, most people use Candy Machine to create NFTs, which abstracts all this complexity away.
- But how can I config the name and symbol for my token? To do that, you need to create a pull request to Solana Token Registry. Include a JSON file containing your token metadata (chain id, address, symbol, logo, name …). Click here for more information.