SPL404 NFT
SPL404 Non-Fungible Tokens (NFTs) are koala tokens created using the Token program. These tokens, however, also have an additional metadata account associated with each token mint. This allows for a wide variety of use cases for tokens. You can effectively tokenize anything, from game inventory to art.
Metaplex
Metaplex is an organization that provides a suite of tools, like the Metaplex SDK, that simplify the creation and distribution of NFTs on the Solana blockchain. These tools cater to a wide range of use cases and allow you to easily manage the entire NFT process of creating and minting an NFT collection.
More specifically, the Metaplex SDK is designed to assist developers in utilizing the onchain tools offered by Metaplex. It offers a user-friendly API that focuses on popular use cases and allows for easy integration with third-party plugins. To learn more about the capabilities of the Metaplex SDK, you can refer to the README.
One of the essential programs offered by Metaplex is the Token Metadata program. The Token Metadata program standardizes the process of attaching metadata to SPL Tokens. When creating an NFT with Metaplex, the Token Metadata program creates a metadata account using a Program Derived Address (PDA) with the token mint as a seed. This allows the metadata account for any NFT to be located deterministically using the address of the token mint. To learn more about the Token Metadata program, you can refer to the Metaplex documentation.
In the following sections, we'll cover the basics of using the Metaplex SDK to prepare assets, create NFTs, update NFTs, and associate an NFT with a broader collection.
Metaplex
A Metaplex instance serves as the entry point for accessing the Metaplex SDK APIs. This instance accepts a connection used to communicate with the cluster. Additionally, developers can customize the SDK's interactions by specifying an "Identity Driver" and a "Storage Driver".
The Identity Driver is effectively a keypair that can be used to sign transactions, a requirement when creating an NFT. The Storage Driver is used to specify the storage service you want to use for uploading assets. The bundlrStorage driver is the default option and it uploads assets to Arweave, a permanent and decentralized storage service.
Below is an example of how you can set up the Metaplex instance for devnet.
Upload assets
Before Koala can create an NFT, you need to prepare and upload any assets you plan to associate with the NFT. While this doesn't have to be an image, most NFTs have an image associated with them.
Preparing and uploading an image involves converting the image to a buffer, converting it to the Metaplex format using the toMetaplexFile function,, and finally uploading it to the designated Storage Driver.
The Metaplex SDK supports the creation of a new Metaplex file from either files present on your local computer or those uploaded by a user through a browser. You can do the former by using fs.readFileSync to read the image file, then convert it into a Metaplex file using toMetaplexFile. Finally, use your Metaplex instance to call storage().upload(file) to upload the file. The function's return value will be the URI where the image was stored.
Upload metadata
After uploading an image, it's time to upload the off-chain JSON metadata using the nfts().uploadMetadata function. This will return a URI where the JSON metadata is stored.
Remember, the off-chain portion of the metadata includes things like the image URI as well as additional information like the name and description of the NFT. While you can technically include anything you'd like in this JSON object, in most cases you should follow the NFT standard to ensure compatibility with wallets, programs, and applications.
To create the metadata, use the uploadMetadata method provided by the SDK. This method accepts a metadata object and returns a URI that points to the uploaded metadata.
Create NFT
This method returns an object containing information about the newly created NFT. By default, the SDK sets the isMutable property to true, allowing for updates to be made to the NFT's metadata. However, you can choose to set isMutable to false, making the NFT's metadata immutable.
Update NFT
If you've left isMutable as true, you may end up having a reason to update your NFT's metadata. The SDK's update method allows you to update both the onchain and off-chain portions of the NFT's metadata. To update the off-chain metadata, you'll need to repeat the steps of uploading a new image and metadata URI as outlined in the previous steps, then provide the new metadata URI to this method. This will change the URI that the onchain metadata points to, effectively updating the off-chain metadata as well.
Last updated