Posted By : Ashish
The introduction of Programmable Non-Fungible Tokens (PNFTs) on Solana brings a new dimension to the world of digital ownership, as it allows creators to insert custom rules into their NFTs. In this way, it becomes possible to ensure that activities like transfers and burns are always done with respect to the creator's true intentions in the Solana development space.
Do Read | How to Create a Compressed NFT on Solana
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.
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
Create and navigate into a new project directory:
bash mkdir pnft_project cd pnft_project
Generate the main TypeScript file for your application:
bash touch app.ts
Use Yarn or npm to initialize your project with default settings:
yarn init -y # or npm init -y
Setup TypeScript with JSON module resolution and target ES2020:
tsc --init --resolveJsonModule --target ES2020
Store your development network Solana keys in a file called guideSecret.json:
Ensure you generate this securely and store safely.
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
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';
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);
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, }));
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'
};
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);
}
}
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
You may also read | A Detailed Guide to NFT Minting on Solana using Metaplex API
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.
November 18, 2024 at 12:45 pm
Your comment is awaiting moderation.