const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
const Web3 = require('web3');
const { web3Provider, oceanConfig } = require('./config');
// Create a web3 instance
const web3 = new Web3(web3Provider);
// Define a function createFRE()
const createFRE = async () => {
const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3);
// Get accounts from web3 instance
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
// data NFT parameters: name, symbol, templateIndex, etc.
tokenURI: 'https://example.com',
// datatoken parameters: name, symbol, templateIndex, etc.
name: "Sample datatoken",
// paymentCollector is the address
paymentCollector: '0x0000000000000000000000000000000000000000',
feeToken: '0x0000000000000000000000000000000000000000',
minter: publisherAccount,
mpFeeAddress: '0x0000000000000000000000000000000000000000'
const fixedPriceParams = {
fixedRateAddress: oceanConfig.fixedRateExchangeAddress,
baseTokenAddress: oceanConfig.oceanTokenAddress,
marketFeeCollector: publisherAccount,
// allowedConsumer: publisherAccount, // only account that consume the exhchange
withMint: false // add FixedPriced contract as minter if withMint == true
// Create data NFT and a datatoken with Fixed Rate exchange
const result = await Factory.createNftErc20WithFixedRate(
// Get the data NFT address and datatoken address from the result
const erc721Address = result.events.NFTCreated.returnValues[0];
const datatokenAddress = result.events.TokenCreated.returnValues[0];
// Call the createFRE() function
.then(({ erc721Address, datatokenAddress }) => {
console.log(`DataNft address ${erc721Address}`);
console.log(`Datatoken address ${datatokenAddress}`);