1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00
docs/developers/ocean.js/creating-datanft.md

79 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2023-05-26 13:50:44 +02:00
# Creating a data NFT
2023-06-29 17:52:01 +02:00
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](../contracts/data-nfts.md).
2023-05-26 13:50:44 +02:00
#### Prerequisites
2023-06-29 17:52:01 +02:00
* [Obtain an API key](../get-api-keys-for-blockchain-access.md)
* [Set up the .env file](configuration.md#create-a-env-file)
* [Install the dependencies](configuration.md#setup-dependencies)
* [Create a configuration file](configuration.md#create-a-configuration-file)
2023-05-26 13:50:44 +02:00
#### Create a script to deploy dataNFT
2023-07-16 09:19:03 +02:00
The provided script demonstrates how to create a data NFT using Oceanjs.
2023-05-26 13:50:44 +02:00
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:
{% tabs %}
{% tab title="create_dataNFT.js" %}
{% code title="create_dataNFT.js" overflow="wrap" %}
2023-05-26 13:50:44 +02:00
```javascript
// 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);
2023-06-09 15:10:40 +02:00
const publisherAddress = await config.publisherAccount.getAddress();
2023-05-26 13:50:44 +02:00
// Define dataNFT parameters
const nftParams = {
name: '72120Bundle',
symbol: '72Bundle',
// Optional parameters
templateIndex: 1,
tokenURI: 'https://example.com',
transferable: true,
2023-06-09 15:10:40 +02:00
owner: publisherAddress
2023-05-26 13:50:44 +02:00
};
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);
});
```
{% endcode %}
Run script:
```bash
node create_dataNFT.js
```
{% endtab %}
{% endtabs %}
2023-10-11 21:40:46 +02:00
* Check out these [code examples](https://github.com/oceanprotocol/ocean.js/blob/main/CodeExamples.md#L0-L1) or [compute to data examples](https://github.com/oceanprotocol/ocean.js/blob/main/ComputeExamples.md#L417) to see how you can use ocean.js.
2023-05-26 13:50:44 +02:00
* If you have any difficulties or if you have further questions about how to use ocean.js please reach out to us on [Discord](https://discord.gg/TnXjkR5).
* If you notice any bugs or issues with ocean.js please [open an issue on github](https://github.com/oceanprotocol/ocean.js/issues/new?assignees=\&labels=bug\&template=bug\_report.md\&title=).
* Visit the [Ocean Protocol website](https://oceanprotocol.com/) for general information about Ocean Protocol.