Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Ocean.js-PlayGround/1.1.1.createDataNFT.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (41 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Import dependencies | |
| const { NftFactory } = require('@oceanprotocol/lib'); | |
| const Web3 = require('web3'); | |
| // Note: Make sure .env file and config.js are created and setup correctly | |
| const { web3Provider, oceanConfig } = require('./config'); | |
| const web3 = new Web3(web3Provider); | |
| // Deinfe a function which will create a dataNFT using Ocean.js library | |
| const createDataNFT = async () => { | |
| // Create a NFTFactory | |
| const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3); | |
| const accounts = await web3.eth.getAccounts(); | |
| const publisherAccount = accounts[0]; | |
| // Define dataNFT parameters | |
| const nftParams = { | |
| name: '72120Bundle', | |
| symbol: '72Bundle', | |
| // Optional parameters | |
| templateIndex: 1, | |
| tokenURI: 'https://example.com', | |
| transferable: true, | |
| owner: publisherAccount | |
| }; | |
| // Call a Factory.createNFT(...) which will create a new dataNFT | |
| const erc721Address = await Factory.createNFT( | |
| publisherAccount, | |
| nftParams | |
| ); | |
| return { | |
| erc721Address | |
| }; | |
| }; | |
| // Call the create createDataNFT() function | |
| createDataNFT() | |
| .then(({ erc721Address }) => { | |
| console.log(`DataNft address ${erc721Address}`); | |
| process.exit(); | |
| }) | |
| .catch((err) => { | |
| console.error(err); | |
| process.exit(1); | |
| }); |