One of my favorite pastimes is exploring new blockchains to understand their features, offerings, and developer-friendliness. Recently, I came across Sui, a blockchain with unique capabilities like dynamic metadata and a focus on seamless user onboarding. After testing it myself, I was impressed by its speed and smooth performance—especially considering it's still under development!
However, I noticed a lack of beginner-friendly guides on minting NFTs on Sui, including common troubleshooting steps. So, I decided to document my experience and create this step-by-step tutorial!
To get started, you'll need:
- Basic knowledge of NodeJS and a text editor like VSCode.
- Familiarity with JavaScript.
Step 1: Setting Up Your NFT with Pinata
While Sui supports dynamic metadata, you still need a service to host your NFT's images, videos, or other media. Pinata is ideal for this because it uses IPFS, ensuring content integrity.
Getting Started with Pinata:
- Sign up for a free account here.
- Upload your NFT media file via the dashboard (Files > Upload > Select File).
- After uploading, copy the CID (Content Identifier) for later use.
Step 2: Configuring the Code with Sui JS SDK
Initialize the Project:
Create a new directory and install the Sui JavaScript SDK:
mkdir sui-nft && cd sui-nft
npm init -y && npm install @mysten/sui.js Update package.json:
Add "type": "module" to enable ES6 imports:
{
"name": "sui-nft",
"type": "module",
"version": "1.0.0",
"dependencies": {
"@mysten/sui.js": "^0.26.1"
}
}Create the Minting Script:
touch mint-nft.js Step 3: Minting the NFT
Import Required Methods:
Open mint-nft.js and add:
import { Ed25519Keypair, JsonRpcProvider, Network, RawSigner } from '@mysten/sui.js';Generate a Wallet Address:
const keypair = new Ed25519Keypair();
const address = "0x" + keypair.getPublicKey().toSuiAddress().toString();
console.log("Wallet Address:", address);Connect to Sui Devnet:
const provider = new JsonRpcProvider(Network.DEVNET);Request Test SUI Tokens:
const fund = await provider.requestSuiFromFaucet(address);
console.log("Airdrop Details:", fund);Merge SUI Tokens (for Gas Efficiency):
Sui treats each token as a separate object. To avoid issues during minting, merge tokens:
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
await wait(3000); // Pause for transaction confirmation
const coin1 = fund.transferred_gas_objects[0].id;
const coin2 = fund.transferred_gas_objects[1].id;
const signer = new RawSigner(keypair, provider);
const mergeTxn = await signer.mergeCoin({
primaryCoin: coin1,
coinToMerge: coin2,
gasBudget: 1000,
});
console.log("Merge Transaction:", mergeTxn);Mint the NFT:
const mintTxn = await signer.executeMoveCall({
packageObjectId: '0x2',
module: 'devnet_nft',
function: 'mint',
arguments: [
'NFT Name', // e.g., 'GM'
'NFT Description', // e.g., 'A nice GM from Pinata & Sui'
'ipfs://YOUR_PINATA_CID_HERE', // Replace with your IPFS link
],
gasBudget: 10000,
});
console.log("Mint Transaction:", mintTxn);
// View the NFT:
const nftId = mintTxn.effects.effects.created[0].reference.objectId;
console.log(`View NFT: https://explorer.sui.io/object/${nftId}?network=devnet`);Step 4: Verify the NFT
Run the script:
node mint-nft.js You’ll receive a Sui Explorer link to view your newly minted NFT!
FAQs
1. Why merge SUI tokens before minting?
Sui’s object model treats each token as distinct. Merging ensures sufficient gas is available from a single object.
2. Can I customize NFT metadata later?
Yes! Sui’s dynamic metadata allows updates post-minting.
3. What’s the cost of minting?
Devnet transactions are free, but mainnet minting requires SUI tokens for gas.
4. How do I transfer the NFT?
Use signer.transferObject() with the NFT’s object ID and recipient address.
👉 Explore more Sui developer tools
Congratulations! You’ve successfully minted an NFT on Sui. Next steps could include:
- Building a Sui NFT marketplace.
- Integrating dynamic metadata updates.
Happy coding! 🚀