Tokens with gage
- solana programs are composable i.e most them sort use this thing call
Factory Patten
- so, this means - The
Program
will allow users to createAccounts
and do special things with those accounts.
SPL Token program
if will look how the factory pattern works in context of SPL token program
SPL Token Program
is the factory forMint Accounts
From
SPL Token Program
users can createMint Accounts
(which will be set asauthority
of that account but still owned bySPL token program
).And from
MInt Accounts
users can createToken Accounts
. Also,Mint Accounts
gonna have theAccounts
,Decimals
,Meta Data
…Mint Account
is a factory forToken Accounts
With
Token Accounts
they can do things likeMint tokens
,Transfer tokens
andBurn Tokens
…more on
SPL Token Program
factory pattern here
Tansfer Tokens
- to transfer tokens users can ask
SPL tokens
to send their tokens(which they got authority on), to other users.
Tokens in context of NFTs
we have
SPL tokens
that are nowtied
toanother program's account
most commonlyMetaPlex
the Metadata program.Non-Fungible tokens - An NFT is simply a
token type where only a single token
has beenminted
.
The Token Program
- Tokens on solana are made and managed using
Solana token program
- one of few programs inSolana Program Library(SPL)
- both regular
tokens
andNFTs
areSolana program library tokens(SPL) tokens
Account relationships
3
essential accounts for token program
1. wallet account
: ur wallet 2. mint account
: stores metadata
about token mint. 3 .token account
: tied to wallet
and stores how many tokens the wallet has.
more here with the image
lets see all 3 one by one
1. Mint Account
- owner of
mint account
isToken Program
- the
metadata
it containsabout the token
are here as follows:mint authority
: theonly account
that cansign
andmint tokens
freeze authority
: theone person
orprogram authority
tofreeze
ormint
.(to mint? is it kinda the same thing with mint authority?)decimal
: Decimals is how many decimal places do we allow tokens to be broken up into - the precision with our tokens. I guess what decimal with2
mean is like you can send32.03
,1.23
its about decimals after the decimal point?supply
: how many tokens exist?is initialized
: it has to do with accountnot with token
. like is this account ready to go?
_It’s pretty standard to set the mint authority to your wallet, mint everything you want, and then remove the mint authority to basically say no more supply will be issued in the future. Alternatively, if you have some kind of dynamic issuance of tokens, it would be common to put them into authority as a program that program manages the minting of tokens.
The freeze authority works the same way._
- more in the image here:
2. Token Accounts (Associated Token Accounts(ATAs))
should be associated with user or wallet. In order to achieve this you will need to create PDA(Program driven Account) which gonna link
user/wallet
andmint account
to thetoken
minted. And that’s gonna get asATAs
the seeds for PDA obviously
user wallet address
andmint account
, token program id is there by default.more with picture here:
The token minting process
step one create a
mint account
step two put up
mint account
andwallet address
to derivePDA
to get Associated Token Account.you can easily do this with the sdk
@solana/spl-token
here is what mint looks like
1 | const mint = await createMint( |
connection
- theJSON-RPC
connection to the clusterpayer
- the keypair of the payer for the transactionmintAuthority
- the account which is authorized to mint new tokensfreezeAuthority
- an account authorized to freeze the tokens in a token account. If you don’t wanna be able to freeze, set it to null!decimals
- specifies the desired decimal precision of the tokenOnce a
mint account
is createdcreate
Associated Token Accounts
mint tokens to the
Associated Token Account
then if u want with
transfer instruction
you can airdrop tokens to different accounts.note: if u wanna mint a token with a different transaction instruction you can do that as well.
Mint tokens on Solana
- Remember these steps:
- create
a mint token account
- create
associated account for the wallet
- you
mint tokens to that wallet
- create
Metaplex
Metaplex
is a metadata store for solanametadata
could beimage
for your token, where thatimage
is stored…Metaplex
is gonna handle all of the associated data for theAssociated token account
- So, from the image above we can see that:
Metaplex
has:Metadata Account
: that’s gonna store metadata about token. This account is usually used forfungible tokens
like USDC or anNFT(non fungible token)
that has the same artwork. Contains the following metadataURI
,Symbol
,Price
,Royalities
,Creators
Master Edition Account
: is used for an NFT that hasone type of artwork
. Different piece of artwork. Also, it has aCollection token account
which is to sayhey this NFT belongs to this specific collection
. Also, aCollection token account
hasAuthority record account
which lets adifferent account(other than a creator)
toadd
NFTs to that specificCollection token account
.
Token Metadata
metadata
is set of data that describes about another dataso,
token metadata
is metadata about the token. likename
,symbol
,logo
…On Solana, NFTs are just like other tokens but
metadata
defines themas NFTs via attributes such as decimals.
attaching metadata to token is done using
Token Metadata Program
. It does this by usingPDAs
that are derived fromMint accounts
Token Metadata Account
stores different info about the
Mint token account
Notice the
URI
property onMetadata account
? - it points tooff-chain
JSON
file, mainly used for NFT. Since theJSON is off-chain
you can storehigh quality
medias.
Token standard
the
off-chain
part followsMetaplex token standard
.we tell what
Token Standard
we’re using usingToken Standard
on-chain field onToken Metadata Account
Token standard
options:NonFungible
: a non-fungile token withMaster Edition
(NFTs)FungibleAsset
: a fungible asset with metadata, that also haveattributes
. AKA,Semi-Fungible
ex: game itemsFungible
: a fungible token with metadata. ex: (USDC, SOL, your own token)NonFungibleEdition
: a non-fungible token withEdition Account
.(printed from Master Edition.Like 1 out of 100
)
Metaplex Token Standard
is widely accepted and various exchanges needs you to conform to it.Here is how it knows which
Token Standard
is being used:- if token has
Master Edition account
it isNonFungible
- if token has
Edition Account
it isNonFungibleEdition
- if token has
NO
Master or Edition Account
,ensuring its supply can be > 1
, and uses0
decimal places - it isFungibleAsset
. Because if you think about it a good example could begame collectibles
and you cannot divide those more than a whole number. You cannot have 2.31 game collectibles. They are represented by whole numbers only. - if token NO
Master or Edition Account
,ensuring its supply can be > 1
and uses atleast1
decimal places, - it isFungible
- if token has
Here is an example of
Fungible token standard
Metaplex SDK
One of the most used SDKs on Solana.
We’ll be using
@metaplex-foundation/js
and@metaplex-foundation/mpl-token-metadata
to createmetadata account associated with our token mint
.general flow for attaching metadata for
FungibleToken
could be sth like this:
- setup Metaplex SDK
- Upload image for the logo
- Upload the off-chain metadata
- Derive the Metadata Account PDA
- Create on-chain Metadata Token Account