This tutorial guides you through the process of creating your own data NFT and a datatoken using Ocean libraries. To know more about data NFTs and datatokens please refer this page. Ocean Protocol supports different pricing schemes which can be set while publishing an asset. Please refer this page for more details on pricing schemes.


Create a script to deploy a data NFT and datatoken with the price schema you chose.

Create a new file in the same working directory where configuration file (config.js) and .env files are present, and copy the code as listed below.

Fees: The code snippets below define fees related parameters. Please refer fees page for more details

The code utilizes methods such as NftFactory and Datatoken from the Ocean libraries to enable you to interact with the Ocean Protocol and perform various operations related to data NFTs and datatokens.

The createFRE() performs the following:

  1. Creates a web3 instance and import Ocean configs.

  2. Retrieves the accounts from the web3 instance and sets the publisher.

  3. Defines parameters for the data NFT, including name, symbol, template index, token URI, transferability, and owner.

  4. Defines parameters for the datatoken, including name, symbol, template index, cap, fee amount, payment collector address, fee token address, minter, and multi-party fee address.

  5. Defines parameters for the price schema, including the fixed rate address, base token address, owner, market fee collector, base token decimals, datatoken decimals, fixed rate, market fee, and optional parameters.

  6. Uses the NftFactory to create a data NFT and datatoken with the fixed rate exchange, using the specified parameters.

  7. Retrieves the addresses of the data NFT and datatoken from the result.

  8. Returns the data NFT and datatoken addresses.

// 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');

// Define a function createFRE()
const createFRE = async () => {

  const FRE_NFT_NAME = 'Datatoken 2'
  const FRE_NFT_SYMBOL = 'DT2'

  let config = await oceanConfig();

  // Create a NFTFactory
  const factory = new NftFactory(config.nftFactoryAddress, config.publisherAccount);

  const nftParams = {
    name: FRE_NFT_NAME,
    symbol: FRE_NFT_SYMBOL,
    templateIndex: 1,
    tokenURI: '',
    transferable: true,
    owner: await config.publisherAccount.getAddress()

  const datatokenParams = {
    templateIndex: 1,
    cap: '100000',
    feeAmount: '0',
    paymentCollector: ZERO_ADDRESS,
    feeToken: ZERO_ADDRESS,
    minter: await config.publisherAccount.getAddress(),
    mpFeeAddress: ZERO_ADDRESS

  const freParams = {
    fixedRateAddress: config.fixedRateExchangeAddress,
    baseTokenAddress: config.oceanTokenAddress,
    owner: await config.publisherAccount.getAddress(),
    marketFeeCollector: await config.publisherAccount.getAddress(),
    baseTokenDecimals: 18,
    datatokenDecimals: 18,
    fixedRate: '1',
    marketFee: '0.001',
    allowedConsumer: ZERO_ADDRESS,
    withMint: true

  const bundleNFT = await factory.createNftWithDatatokenWithFixedRate(
  const trxReceipt = await bundleNFT.wait()
  return {

// Call the createFRE() function 
  .then(({ trxReceipt }) => {
    console.log(`TX Receipt ${trxReceipt}`);
  .catch((err) => {

Execute script

node create_datatoken_with_fre.js

By utilizing these dependencies and configuration settings, the script can leverage the functionalities provided by the Ocean libraries and interact with the Ocean Protocol ecosystem effectively.

Last updated


Copyright 2024 Ocean Protocol Foundation Ltd.