Overview Of Solang Solidity Solana SPL Fungible Token Minter Program

Introduction:

In this lesson, we will go over the Solang Solidity Solana SPL program for the token minter dApp.

Remember, watching the lesson video will offer a deeper understanding of this topic.

Learning Objectives:

By the end of this lesson, you will be able to:

  1. Access the Repo for this course
  2. Be familiar with how a Solang Solidity for Solana SPL token minter program is structured.

Lesson Video:


Repo for Solang Solidity Solana SPL Fungible Token Minter Program:

As we move on in this course, I will be taking you by hand together to build the token minter dApp. To make it easier to follow along, I have made a repo in which you need to do the following steps with to ensure you can follow along.

Also, this will be essential to complete your project for this course later on.

STEP 1: Go to the repo at Solang Solidity for Solana Course 201 Repo

STEP 2: Star it⭐ and then fork the repo

STEP 3: Clone your forked version of the repo to your computer so that you can make changes and push changes to it gradually as we move on throughout the course

STEP 4: Make a new branch before making changes and name it “project-dapp-frontend” (copy-paste the branch name to avoid typo errors).

You will push future changes as PR from the new branch to the main branch of your own forked repo (not the course official repo you forked).

This is a good practice when contributing to either your personal project, organization or other open-sourced project on GitHub.

STEP 5: Run the Solana Program with the following commands (/program)

Open a terminal in VSCode and run the following command to install the Solana program dependencies like Anchor, Webjs and others:

cd program

Then:

pnpm i

STEP 6: Run the Frontend of the dApp (/app)

Open a second terminal (without closing the first one above for the Solana program folder) in VSCode and run the following command to install the Nextjs and Solana program dependencies like Typescript, Webjs and others:

cd app

Then:

pnpm i

Then run the Nextjs frontend in your browser with:

pnpm dev

This will help to see the dApp in your browser and interact with it as we move on in this course.

For now, it might load with a plain page or some errors. Kindly ignore this for now as things will work as we progress from one lesson to another.

What is the Solang Solidity Solana SPL Fungible Token Minter Program?

This Solana program was written in Solang Solidity, which allows developers to develop smart contracts using Solidity on Solana.

It contains 2 main functions:

  1. createMintToken: help create the token mint which is a token account on Solana.
  2. mint_to: helps to mint the SPL token by first creating an associate token account (ATA). And then mint into it.

Code for Solang Solidity Solana SPL Fungible Token Minter Program:

import "../libraries/spl_token.sol";
import "../libraries/mpl_metadata.sol";

// @program_id("GbWt4JoWpfAXEeNEkrDyinpkwz3tPB3KCUY98abFTXr4")
// @program_id("5ybfMJsmwm2TC2dAEgUsiRioirxwYhLsehH9ukusHJn")
@program_id("SPEvBpsQ5Gm2HnSkJyKL8GAKTUkHaumwAgSFYcv7mAB")


contract spl_token_minter {
    @payer(payer)
    constructor() {}

    @mutableSigner(payer) // payer account
    @mutableSigner(mint) // mint account to be created
    @mutableAccount(metadata) // metadata account to be created
    @signer(mintAuthority) // mint authority for the mint account
    @account(rentAddress)
    @account(metadataProgramId)
    function createTokenMint(
        address freezeAuthority, // freeze authority for the mint account
        uint8 decimals, // decimals for the mint account
        string name, // name for the metadata account
        string symbol, // symbol for the metadata account
        string uri // uri for the metadata account
    ) external {
        // Invoke System Program to create a new account for the mint account and,
        // Invoke Token Program to initialize the mint account
        // Set mint authority, freeze authority, and decimals for the mint account
        SplToken.create_mint(
            tx.accounts.payer.key,            // payer account
            tx.accounts.mint.key,            // mint account
            tx.accounts.mintAuthority.key,   // mint authority
            freezeAuthority, // freeze authority
            decimals         // decimals
        );

        // Invoke Metadata Program to create a new account for the metadata account
        MplMetadata.create_metadata_account(
            tx.accounts.metadata.key, // metadata account
            tx.accounts.mint.key,  // mint account
            tx.accounts.mintAuthority.key, // mint authority
            tx.accounts.payer.key, // payer
            tx.accounts.payer.key, // update authority (of the metadata account)
            name, // name
            symbol, // symbol
            uri, // uri (off-chain metadata json)
            tx.accounts.rentAddress.key,
            tx.accounts.metadataProgramId.key
        );
    }

    @mutableAccount(mint)
    @mutableAccount(tokenAccount)
    @mutableSigner(mintAuthority)
    function mintTo(uint64 amount) external {
        // Mint tokens to the token account
        SplToken.mint_to(
            tx.accounts.mint.key, // mint account
            tx.accounts.tokenAccount.key, // token account
            tx.accounts.mintAuthority.key, // mint authority
            amount // amount
        );
    }
}

Note: This is an extracted code from the Solang Solidity for Solana 101 course, check it under the resources below if want to learn more about this code.

Conclusion:

In this lesson, you’ve learned about the overview Of Solang Solidity Solana SPL Fungible Token Minter Program.

Resources & References:

To deepen your understanding of this lesson, you can explore the following resources:

  1. Ultimate Guide To Create Solana SPL (Fungible) Token Program In Solidity With Solang And Anchor
  2. Solang Solidity for Solana 101 course

Support:

If you need help with this lesson, questions, suggestions and improvement. The best way to get help is to use the comment below:
1. First check existing comments if your questions have been answered before posting.
2. If no existing related question with an answer, then you can post a new one (kindly avoid duplicating previously asked and answered questions).

NOTE: This is the most recommended way of getting support directly from the instructor of this course. Posting on other platforms like Discord may get support from other community members and not from the course instructor directly.

Images|Videos|Links: To support your question with a screenshot, Github repo link or other media, kindly upload it somewhere online like Drive/Dropbox or Github (for codes) first, then post the link to it in your comment. Please do not upload media/codes directly, it may fail or cause your comment to be deleted.

Please ONLY post questions that are specific to this lesson not the entire course to ensure others can find it helpful. Each lesson allows comments relating to it ONLY. Off-lesson questions will be deleted even if they relate to this course as a whole but as long as they are not specific to this lesson, they are not allowed.

Post a comment

Leave a Comment

By using this website you agree to accept our Privacy Policy and Terms & Conditions