date
Jul 9, 2024
slug
create-solana-token
status
Published
tags
Solana
NodeJs
summary
• You may recall SOL is the 'native token' of Solana. All other tokens, fungible and non-fungible tokens (NFTs), are called SPL Tokens
• The Token Program contains instructions for creating and interacting with SPL Tokens
• Token Mints are accounts that define a specific token. This includes information about the token itself (like how many decimals it has), the account allowed to mint more tokens (called the mint authority), and where to find more information about the token like a description, image, etc. The mint authority can use the token mint to make more tokens!
• Token Accounts hold tokens of a specific Token Mint. For most users, their balances of each token mint are stored in Associated Token Accounts - accounts with addresses made from their wallet address and the token's mint.
• Creating Token Mints and Token Accounts requires allocating rent in SOL. The rent for a Token Account can be refunded when the account is closed, however, Token Mints currently cannot be closed.
type
Post
Token Mint
The createAccount function returns the publicKey of the new token account. This function requires the following arguments:
- connection - the JSON-RPC connection to the cluster
- payer - the account of the payer for the transaction
- mint - the token mint that the new token account is associated with
- owner - the account of the owner of the new token account
- keypair - this is an optional parameter for specifying the new token account address. If no keypair is provided, the createAccount function defaults to a derivation from the associated mint and owner accounts.
Mint Tokens
The mintTo function returns a TransactionSignature that can be viewed on the Solana Explorer. The mintTo function requires the following arguments:
- connection - the JSON-RPC connection to the cluster
- payer - the account of the payer for the transaction
- mint - the token mint that the new token account is associated with
- destination - the token account that tokens will be minted to
- authority - the account authorized to mint tokens
- amount - the raw amount of tokens to mint outside of decimals, e.g. if Scrooge Coin mint's decimals property was set to 2 then to get 1 full Scrooge Coin you would need to set this property to 100
Transfer Tokens