Creating a data NFT

This tutorial guides you through the process of creating your own data NFT using Ocean libraries. To know more about data NFT please refer this page.

Prerequisites

Create a script to deploy dataNFT

The provided script demonstrates how to create a data NFT using Oceanjs.

First, create a new file in the working directory, alongside the config.js and .env files. Name it create_dataNFT.js (or any appropriate name). Then, copy the following code into the new created file:

create_dataNFT.js
// Note: Make sure .env file and config.js are created and setup correctly
const { oceanConfig } = require('./config.js');
const { ZERO_ADDRESS, NftFactory } = require ('@oceanprotocol/lib');

// Deinfe a function which will create a dataNFT using Ocean.js library
const createDataNFT = async () => {
  let config = await oceanConfig();
  // Create a NFTFactory
  const factory = new NftFactory(config.nftFactoryAddress, config.publisherAccount);

  const publisherAddress = await config.publisherAccount.getAddress();

  // Define dataNFT parameters
  const nftParams = {
    name: '72120Bundle',
    symbol: '72Bundle',
    // Optional parameters
    templateIndex: 1,
    tokenURI: 'https://example.com',
    transferable: true,
    owner: publisherAddress
  };

  const bundleNFT = await factory.createNFT(nftParams);

  const trxReceipt = await bundleNFT.wait()

  return {
    trxReceipt
  };
};

// Call the create createDataNFT() function
createDataNFT()
  .then(({ nftAddress }) => {
    console.log(`DataNft address ${nftAddress}`);
    process.exit();
  })
  .catch((err) => {
    console.error(err);
    process.exit(1);
  });

Run script:

node create_dataNFT.js

Last updated

Logo

Copyright 2024 Ocean Protocol Foundation Ltd.