Exploration and practice of Solana NFT as an identification verification tool

robot
Abstract generation in progress

Exploring the Use of Solana Token as an identification verification Tool

NFT, as a "non-fungible" token, is very suitable for use as an identification verification tool. This article will explore the feasibility of using NFT as a registration certificate through a simple example.

Introduction

Before we begin, let’s introduce the tools that will be used.

SPL Token

We can directly use the generic implementation Token Program provided by Solana without having to write a new Solana contract from scratch. The Token Program is part of the Solana Program Library(SPL), which offers multiple commonly used program implementations including Token, Swap, and Memo, and provides a complete set of client libraries, CLI tools, etc., greatly facilitating Solana developers.

Solana Playground

Solpy provides an online environment for writing and deploying Solana contracts, and by default includes some commonly used tools, such as the SPL Token introduced earlier. We can easily create and manage tokens using spl-token-cli.

Web3 Beginner Series: Exploring Login with Solana Token

Auth Token

In this section, we will create an NFT Token. If the user mints the Token, it is assumed that this wallet address is registered in the system; otherwise, prompt the user to register first.

Now, let's start with the On-chain part:

Create Token

We use spl-token to create a new token and specify it as a non-divisible Token( just like an NFT) through "--decimals".

Web3 Beginner Series: Exploring Login with Solana Token

Create Token Account

Next, we need to create a Token Account for the Token created in the previous step.

Web3 Beginner Series: Exploring Login with Solana Token

mint

Before minting a new Token to other wallet addresses, let's first try to mint a Token unit for the newly created Token Account.

Web3 Beginner Series: Exploring Login with Solana Token

We can also try to directly mint tokens to a wallet address.

Web3 Beginner Series: Explore Logging in with Solana Token

is the wallet address for minting

According to the original plan, we should mint for other wallet addresses that do not belong to us. We need to first create a Token Account for the wallet address, and then use the created Token Account to mint new Token units.

Web3 Beginner Series: Exploring Login with Solana Token

In short, if we want to mint a Token unit for a certain wallet address, we must first create a Token Account for that wallet address.

Get Token Account

We need to use the RPC interface to check whether a certain wallet address has minted the NFT we created. Specifically, we will query the data using the "getTokenAccountsByOwner" method.

Web3 Beginner Series: Exploring Login with Solana Token

Implementation

Through the above attempts, we can use existing capabilities to achieve the required functionality. Next, let's start writing the client code.

We will create a simple Nextjs project to implement it, using Ant Design Web3 to Connect Wallet.

page implementation

We need three pages including the homepage, used to connect the wallet and check if the user has registered ( to mint NFT ), as well as to let the user go through the registration process to mint NFT (.

After opening the demo page, you will first see the welcome message and a link to the Sign in page. Once on the page, you need to Sign in first. Clicking "Continue with Solana" will prompt the wallet. If you haven't registered before, you will be prompted to register first.

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-57805e7852a7ca66850a8d6b27398250.webp(

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-14368232303f480fe96b88d4a6ba1f55.webp(

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-ff77873087f76c412229207de916e9b9.webp(

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-eb80585bdf5e8c2b3e3392b4bf84b693.webp(

On the Sign on page, after connecting the wallet, if successful, you will see a success message.

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-16d560890fd229d1bb393bbc10a67f18.webp(

) transaction verification

NFTs, we can see the Mint operation that was just performed internally during sign-on as well as the minted NFT.

![Web3 Beginner Series: Exploring Login with Solana Token]###https://img-cdn.gateio.im/webp-social/moments-f7eeea08c0467dfcfc5f1c37626332ee.webp(

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-18ae3f01f44c19832db49546fbedfe09.webp(

![Web3 Beginner Series: Exploring Login with Solana Token])https://img-cdn.gateio.im/webp-social/moments-27ab4429c1cd10ab43040def7400cc54.webp(

Summary

We created an NFT using spl-token-cli, and then determined whether a wallet address has a Token Account and has minted tokens to ascertain if it has registered on the website.

When Web3 users connect their wallets, we automatically send a sign-on request, internally create a Token Account, and mint a Token unit as proof of the user's registration.

After that, the user can log in to the website again using the same wallet address.

SOL-3.42%
View Original
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • 3
  • Share
Comment
0/400
ChainWatchervip
· 1h ago
This proposal is worth studying in depth.
View OriginalReply0
OnlyOnMainnetvip
· 07-28 14:29
Refreshing log in, truly赞
View OriginalReply0
SmartMoneyWalletvip
· 07-27 16:12
A very practical research direction
View OriginalReply0
Trade Crypto Anywhere Anytime
qrCode
Scan to download Gate app
Community
English
  • 简体中文
  • English
  • Tiếng Việt
  • 繁體中文
  • Español
  • Русский
  • Français (Afrique)
  • Português (Portugal)
  • Bahasa Indonesia
  • 日本語
  • بالعربية
  • Українська
  • Português (Brasil)