How to Develop Programmable Non-Fungible Tokens on Solana

How to Develop Programmable Non-Fungible Tokens on Solana

The introduction of Programmable Non-Fungible Tokens (PNFTs) on Solana is what brings in a new dimension to the world of digital ownership, as it allows creators to insert custom rules into their NFTs. Through advanced NFT development services, it becomes possible to ensure that activities like transfers and burns are always done with respect to the creator’s true intentions.

Key Features of PNFTs

Enhanced Security: For any operation, PNFTs demand that such an action must go through the Token Metadata program, ensuring that no set rules by the creator are bypassed as they might be using the SPL token program.

Granular Delegation: Creators can determine precise operations allowed on assets, and assign delegates who have detailed security systems for managing these permissions.

Rule Enforcement: Any operation upon which PNFT is enforced may be subjected to diverse custom rules thus allowing inventors to put various prerequisites regarding actions like transfer and update into effect.

Practical Applications

Royalty Enforcement: These tokens can enforce payments for royalties by using rules such as those that prevent transfers unless they comply with imposed royalty terms. This perspective on NFTs lets artists claim more control over how their digital assets are used or transferred.

Step 1: Project Setup

Initialize Project Directory

Create and navigate into a new project directory:

bash mkdir pnft_project cd pnft_project

Create TypeScript File

Generate the main TypeScript file for your application:

bash touch app.ts

Initialize Package

Use Yarn or npm to initialize your project with default settings:

yarn init -y # or npm init -y

TypeScript Configuration

Setup TypeScript with JSON module resolution and target ES2020:

tsc --init --resolveJsonModule --target ES2020

Paper Wallet Setup

Store your development network Solana keys in a file called guideSecret.json:

Ensure you generate this securely and store safely.

Step 2: Install Dependencies

Install necessary libraries for interacting with Solana’s blockchain:

yarn add @solana/web3.js @metaplex-foundation/js or npm install @solana/web3.js @metaplex-foundation/js

Step 3: Configure Your App

Import Required Modules

At the top of app.ts, include the necessary modules from the installed libraries: typescript

import { Connection, Keypair, PublicKey } from "@solana/web3.js"; import { Metaplex, keypairIdentity, bundlrStorage, toMetaplexFile, toBigNumber } from "@metaplex-foundation/js"; import { TokenStandard } from '@metaplex-foundation/mpl-token-metadata'; import secret from './guideSecret.json';

Setup Connection

Configure the connection to the Solana cluster using an endpoint:

const QUICKNODE_RPC = 'https://example.solana-devnet.quiknode.pro/your_unique_id/'; const SOLANA_CONNECTION = new Connection(QUICKNODE_RPC);

Initialize Metaplex

Set up the Metaplex client with the connection and wallet information:

const WALLET = Keypair.fromSecretKey(new Uint8Array(secret)); const METAPLEX = Metaplex.make(SOLANA_CONNECTION) .use(keypairIdentity(WALLET)) .use(bundlrStorage({ address: 'https://devnet.bundlr.network', providerUrl: QUICKNODE_RPC, timeout: 60000, }));

Step 4: Define NFT Configuration

Configure the metadata and attributes of your NFT: typescript

const NFT_CONFIG = { imgName: 'MyUniqueNFT', symbol: 'UNIQ', sellerFeeBasisPoints: 500, // 5% fee creators: [{ address: WALLET.publicKey, share: 100 }], metadata: 'https://arweave.net/example_URI' };

Step 5: Create the Mint Function

Implement the function to mint your pNFT: typescript

async function mintProgrammableNft( metadataUri: string, name: string, sellerFee: number, symbol: string, creators: { address: PublicKey, share: number }[] ) { console.log("Minting pNFT..."); try { const transactionBuilder = await METAPLEX.nfts().builders().create({ uri: metadataUri, name: name, sellerFeeBasisPoints: sellerFee, symbol: symbol, creators: creators, isMutable: true, isCollection: false, tokenStandard: TokenStandard.ProgrammableNonFungible, ruleSet: null }); let { signature, confirmResponse } = await METAPLEX.rpc().sendAndConfirmTransaction(transactionBuilder); if (confirmResponse.value.err) { throw new Error('Failed to confirm transaction'); } const { mintAddress } = transactionBuilder.getContext(); console.log(` Success!🎉`); console.log(` Minted NFT: https://explorer.solana.com/address/${mintAddress.toString()}?cluster=devnet`); console.log(` Tx: https://explorer.solana.com/tx/${signature}?cluster=devnet`); } catch (err) { console.log(err); } }

Step 6: Mint the NFT

Execute the minting process by calling your function with the configured settings: typescript

mintProgrammableNft( NFT_CONFIG.metadata, NFT_CONFIG.imgName, NFT_CONFIG.sellerFeeBasisPoints, NFT_CONFIG.symbol, NFT_CONFIG.creators ); // Run the script ts-node app.ts

Conclusion

Programmable NFTs on Solana offer NFT developers an innovative, fast, and secure platform to create advanced and customizable decentralized applications, revolutionizing the digital asset landscape. Contact our NFT developers for expert services.

References — Github : https://github.com/