Mint Metaplex Core NFTs for characters
Introduction
Honeycomb Protocol lets you create and mint NFTs for your users. You can use these NFTs to represent in-game assets, characters, or any other digital asset you want to tokenize.
Why Metaplex Core NFTs?
Metaplex Core is the new Solana NFT standard that makes minting NFTs not only super simple, but also reduces the costs significantly by using a single account design.
Minting Metaplex Core NFTs is a great ideas when you want to have both in-game assets and an on-chain collection of tokens outside of Honeycomb Protocol (e.g., to own and trade on the main Solana network).
In this guide, we will show you how to mint core NFTs using Metaplex and make a compressed character out of them.
Pre-requisites
Before you start, make sure you have the following:
Making any transactions on the Honeynet (our test RPC) would require having Honeynet SOL in your wallet. So make sure to fund your wallet on Honeynet before proceeding with this guide.
You can do so using the following command if you haven't already.
solana airdrop <amount> <wallet address> -u https://rpc.test.honeycombprotocol.com
Step by step guide
Step 1: Install the required packages
- NPM
- Yarn
npm install @solana/web3.js @metaplex-foundation/mpl-core @metaplex-foundation/umi-bundle-defaults @metaplex-foundation/umi @metaplex-foundation/mpl-token-metadata @metaplex-foundation/umi-web3js-adapters @honeycomb-protocol/edge-client
yarn add @solana/web3.js @metaplex-foundation/mpl-core @metaplex-foundation/umi-bundle-defaults @metaplex-foundation/umi @metaplex-foundation/mpl-token-metadata @metaplex-foundation/umi-web3js-adapters @honeycomb-protocol/edge-client
Step 2: Instantiate Edge client and Umi
We will be using the Umi framework of Metaplex to mint the NFTs. To get started, instantiate Edge client and Umi with the required plugins like so.
// mintAndWrap.ts
import * as web3 from "@solana/web3.js";
import fs from "fs";
import path from "path";
import { createEdgeClient } from "@honeycomb-protocol/edge-client";
import { sendTransactions } from "@honeycomb-protocol/edge-client/client/helpers"
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { mplCore, createCollection, createV1 } from "@metaplex-foundation/mpl-core";
import { mplTokenMetadata } from "@metaplex-foundation/mpl-token-metadata";
import { keypairIdentity, TransactionBuilderSendAndConfirmOptions, generateSigner } from "@metaplex-foundation/umi";
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
const RPC_URL = "https://rpc.test.honeycombprotocol.com/";
const API_URL = "https://edge.test.honeycombprotocol.com/";
const client = createEdgeClient(API_URL, true);
// Import your secret key to use with Umi to sign and pay for transactions
const authority = web3.Keypair.fromSecretKey(
Uint8Array.from(
JSON.parse(
fs.readFileSync(path.resolve(__dirname, "key.json"), "utf8")
)
)
);
const umi = createUmi(RPC_URL)
.use(mplCore())
.use(mplTokenMetadata())
.use(keypairIdentity(fromWeb3JsKeypair(authority), true));
// Options for when sending the transaction to mint the NFT through Umi
const options: TransactionBuilderSendAndConfirmOptions = {
confirm: {
commitment: "confirmed",
},
send: {
skipPreflight: true,
}
};
Step 3: Mint NFTs
Having set up the Edge Client and Umi instances, you can now mint NFTs. Here is an example of how you can mint NFTs.
- Single NFT
- Collection
// mintAndWrap.ts
// ...Previous imports and code
async function main() {
const mints: Array<string> = [];
const nftAddress = generateSigner(umi);
try {
await createV1(umi, {
asset: nftAddress,
uri: "https://example.com/my-nft.json", // Make sure to upload the metadata and use the link here
name: `Test Mpl Core Nft`,
owner: umi.identity.publicKey,
}).sendAndConfirm(umi, options);
mints.push(nftAddress.publicKey);
console.log(`NFT minted at ${nftAddress.publicKey}`);
} catch (error) {
console.error("Error:", error);
}
}
main();
// mintAndWrap.ts
// ...Previous imports and code
async function main() {
const collectionAddress = generateSigner(umi);
const nftAddresses = new Array(10).fill("").map(() => generateSigner(umi));
const mints: Array<string> = []; // The address of each NFT will be stored in this array as it gets minted
try {
await createCollection(umi, {
collection: collectionAddress,
name: "My Collection",
uri: "https://example.com/my-collection.json", // Make sure to upload the metadata and use the link here
}).sendAndConfirm(umi, options);
console.log(`Collection created at ${collectionAddress.publicKey}`)
for (let i = 0; i < nftAddresses.length; i++) {
await createV1(umi, {
asset: nftAddresses[i],
name: `Test Mpl Core Nft #${i + 1}`,
uri: "https://example.com/my-nft.json", // Make sure to upload the metadata and use the link here
collection: collectionAddress.publicKey,
owner: umi.identity.publicKey,
}).sendAndConfirm(umi, options);
mints.push(nftAddresses[i].publicKey);
console.log(`NFT #${i + 1} minted at ${nftAddresses[i].publicKey}`)
}
} catch (error) {
console.error("Error:", error);
}
}
main();
You can now use these NFTs to represent your in-game assets or characters.
Step 4: Wrap the NFT(s) into character(s)
const { createWrapAssetsToCharacterTransactions: transactions } =
await client.createWrapAssetsToCharacterTransactions({
project: "Your Project Address in string format",
characterModel: "Your Character Model Address in string format",
mintList: mints, // NFT addresses array
wallet: authority.publicKey.toString(), // Wallet public key as string
});
const response = await sendTransactions(client, transactions, [authority]);
console.log(response);
That's it! You have successfully minted core NFTs using Metaplex and created Honeycomb characters using them. Along with wrapping, you can also assemble characters using your NFTs.
For a more detailed understanding, please head to our Characters section.
How our compressed character works
The characters tree is used to store the characters, along with their ownership information and any other additional info. There are three methods you can use to create a character on Honeycomb:
- Wrapping freezes the NFT and creates a new Honeycomb character from it.
- Assembling with an NFT lets you take over the update authority for that NFT and creates a new Honeycomb character.
- Lastly, you can also assemble a Honeycomb native character without an NFT. This will not require the user to have an NFT in their wallet, and creates a Honeycomb character with the same functionality as the previous two options.
Regardless of the method you use, the character's compressed account is stored in the merkle tree, and we handle all of the proofs for you.
Below is a flow diagram of the entire process of wrapping/assembling a character.
- Wrapping
- Assembling