store(token)
method is used to store NFT assets and metadata. It takes a single token
argument, which contains the metadata for your NFT as a JavaScript object.import W3IpfsClient from 'aioz-w3ipfs-sdk';
import fs from 'fs';
// Initialize the client with your API key
let client = new W3IpfsClient("key", "secret-key")
const readableStreamForFile = fs.createReadStream('./test.png');
// Example metadata object
const metadata = {
name: "My Awesome NFT",
description: "This is an NFT that represents my creativity as a digital artist!",
image: null,
properties: {
type: "image",
origins: {
http: "https://.../",
ipfs: "ipfs://Qm..."
},
authors: [
{ name: "Author" }
],
content: {
"text/markdown": "Lorem ipsum dolor sit amet, consectetur adipiscing elit..."
}
}
}
const options = {
w3IpfsMetadata: {
name: "My Awesome NFT",
keyvalues: {
customKey: 'customValue',
customKey2: 'customValue2'
}
}
};
// Store the NFT assets and metadata
async function storeNFT() {
const result = await client.pinNft(readableStreamForFile, metadata, undefined, options)
console.log('Result: ', result)
}
storeNFT()
store
method to store the NFT assets and metadata. The method returns the metadata URI, which you can use in the minting process.// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "ERC1155.sol";
contract MyNFT is ERC1155 {
uint256 public tokenCounter;
constructor() ERC1155("") {
tokenCounter = 0;
}
function mintNFT(string memory _metadataURI) public {
tokenCounter++;
_mint(msg.sender, tokenCounter, 1, "");
_setURI(tokenCounter, _metadataURI);
}
}
mintNFT
function is called to mint a new token. It increments the tokenCounter
, mints a token with the new ID, and sets the metadata URI using the _setURI
function.ipfs://Qm...
) as the _metadataURI
parameter in the minting transaction.ON THIS PAGE