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.2.2.createAndMintDatatoken.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
84 lines (72 sloc)
2.1 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
| const { NftFactory, Datatoken } = require('@oceanprotocol/lib'); | |
| const Web3 = require('web3'); | |
| const { web3Provider, oceanConfig } = require('./config'); | |
| const web3 = new Web3(web3Provider); | |
| const createDataNFT = async () => { | |
| const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3); | |
| const accounts = await web3.eth.getAccounts(); | |
| const publisherAccount = accounts[0]; | |
| const nftParams = { | |
| name: '72120Bundle', | |
| symbol: '72Bundle', | |
| templateIndex: 1, | |
| tokenURI: 'https://example.com', | |
| transferable: true, | |
| owner: publisherAccount | |
| }; | |
| const erc20Params = { | |
| templateIndex: 1, | |
| cap: '100000', | |
| feeAmount: '0', | |
| paymentCollector: '0x0000000000000000000000000000000000000000', | |
| feeToken: '0x0000000000000000000000000000000000000000', | |
| minter: publisherAccount, | |
| mpFeeAddress: '0x0000000000000000000000000000000000000000' | |
| }; | |
| const result = await Factory.createNftWithErc20( | |
| publisherAccount, | |
| nftParams, | |
| erc20Params | |
| ); | |
| const erc721Address = result.events.NFTCreated.returnValues[0]; | |
| const datatokenAddress = result.events.TokenCreated.returnValues[0]; | |
| return { | |
| erc721Address, | |
| datatokenAddress | |
| }; | |
| }; | |
| const mintDatatoken = async (datatokenAddress) => { | |
| const accounts = await web3.eth.getAccounts(); | |
| const publisherAccount = accounts[0]; | |
| const consumerAccount = publisherAccount; | |
| const datatoken = new Datatoken(web3); | |
| await datatoken.mint( | |
| datatokenAddress, | |
| publisherAccount, | |
| '1', | |
| consumerAccount | |
| ); | |
| const consumerBalance = await datatoken.balance( | |
| datatokenAddress, | |
| consumerAccount | |
| ); | |
| console.log(`Consumer balance ${consumerBalance}`); | |
| }; | |
| createDataNFT() | |
| .then(({ erc721Address, datatokenAddress }) => { | |
| console.log(`DataNft address ${erc721Address}`); | |
| console.log(`Datatoken address ${datatokenAddress}`); | |
| mintDatatoken(datatokenAddress) | |
| .then(() => { | |
| console.log('Done'); | |
| process.exit((err) => { | |
| console.error(err); | |
| process.exit(1); | |
| }); | |
| }) | |
| .catch(); | |
| }) | |
| .catch((err) => { | |
| console.error(err); | |
| process.exit(1); | |
| }); |