2022-08-02 14:52:51 +02:00
# Create datatoken with fixed pricing
2022-07-25 12:17:51 +02:00
2022-08-03 12:32:21 +02:00
This tutorial guides you through the process of creating your own data NFT and a datatoken with fixed pricing, using Ocean libraries. To know more about data NFTs and datatokens please refer [this page ](../../core-concepts/datanft-and-datatoken.md ). Ocean Protocol supports different pricing schemes which can be set while publishing an asset. Please refer [this page ](../../core-concepts/asset-pricing.md ) for more details on pricing schemes.
2022-08-02 11:59:29 +02:00
2022-08-03 12:31:26 +02:00
#### Prerequisites
2022-07-25 12:17:51 +02:00
2022-08-03 12:31:18 +02:00
- [Obtain an API key ](configuration.md#obtaining-api-key-for-ethereum-node-provider )
- [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 )
2022-07-25 12:17:51 +02:00
2022-08-02 14:52:51 +02:00
#### Create a script to deploy data NFT and datatoken with fixed pricing.
2022-07-25 12:17:51 +02:00
2022-08-02 11:59:29 +02:00
Create a new file in the same working directory where configuration file (`config.py`/`config.js`) and `.env` files are present, and copy the code as listed below.  
2022-08-02 15:38:06 +02:00
{% hint style="info" %}
**Fees**: The code snippets below define fees related parameters. Please refer [fees page ](../../core-concepts/fees.md )for more details
{% endhint %}
2022-07-25 12:17:51 +02:00
{% tabs %}
{% tab title="ocean.js" %}
{% code title="create_datatoken_with_fre.js" %}
```javascript
2022-08-02 14:52:51 +02:00
// Import dependencies
2022-07-25 12:17:51 +02:00
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
const Web3 = require('web3');
const { web3Provider, oceanConfig } = require('./config');
2022-08-02 14:52:51 +02:00
// Create a web3 instance
2022-07-25 12:17:51 +02:00
const web3 = new Web3(web3Provider);
2022-08-02 14:52:51 +02:00
// Define a function createFRE()
const createFRE = async () => {
2022-07-25 12:17:51 +02:00
const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3);
2022-08-02 14:52:51 +02:00
// Get accounts from web3 instance
2022-07-25 12:17:51 +02:00
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
2022-08-02 14:52:51 +02:00
// data NFT parameters: name, symbol, templateIndex, etc.
2022-07-25 12:17:51 +02:00
const nftParams = {
name: '72120Bundle',
symbol: '72Bundle',
templateIndex: 1,
tokenURI: 'https://example.com',
transferable: true,
owner: publisherAccount
};
2022-08-02 14:52:51 +02:00
// datatoken parameters: name, symbol, templateIndex, etc.
2022-07-25 12:17:51 +02:00
const erc20Params = {
2022-08-02 14:52:51 +02:00
name: "Sample datatoken",
symbol: "SDT",
2022-07-25 12:17:51 +02:00
templateIndex: 1,
cap: '100000',
feeAmount: '0',
2022-08-02 14:52:51 +02:00
// paymentCollector is the address
2022-07-25 12:17:51 +02:00
paymentCollector: '0x0000000000000000000000000000000000000000',
feeToken: '0x0000000000000000000000000000000000000000',
minter: publisherAccount,
mpFeeAddress: '0x0000000000000000000000000000000000000000'
};
const fixedPriceParams = {
fixedRateAddress: oceanConfig.fixedRateExchangeAddress,
baseTokenAddress: oceanConfig.oceanTokenAddress,
owner: publisherAccount,
marketFeeCollector: publisherAccount,
baseTokenDecimals: 18,
datatokenDecimals: 18,
2022-08-02 11:59:29 +02:00
fixedRate: '100',
2022-07-25 12:17:51 +02:00
marketFee: '0',
2022-08-02 14:52:51 +02:00
// Optional parameters
// allowedConsumer: publisherAccount, // only account that consume the exhchange
withMint: false // add FixedPriced contract as minter if withMint == true
2022-07-25 12:17:51 +02:00
}
2022-08-02 14:52:51 +02:00
// Create data NFT and a datatoken with Fixed Rate exchange
2022-07-25 12:17:51 +02:00
const result = await Factory.createNftErc20WithFixedRate(
publisherAccount,
nftParams,
erc20Params,
fixedPriceParams
);
2022-08-02 14:52:51 +02:00
// Get the data NFT address and datatoken address from the result
2022-07-25 12:17:51 +02:00
const erc721Address = result.events.NFTCreated.returnValues[0];
const datatokenAddress = result.events.TokenCreated.returnValues[0];
return {
erc721Address,
datatokenAddress
};
};
2022-08-02 14:52:51 +02:00
// Call the createFRE() function
createFRE()
2022-07-25 12:17:51 +02:00
.then(({ erc721Address, datatokenAddress }) => {
console.log(`DataNft address ${erc721Address}`);
console.log(`Datatoken address ${datatokenAddress}`);
process.exit(1);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
2022-08-02 11:59:29 +02:00
Execute script
```
node create_datatoken_with_fre.js
```
2022-07-25 12:17:51 +02:00
{% endtab %}
{% tab title="ocean.py" %}
{% code title="create_datatoken_with_fre.py" %}
```python
# Note: Ensure that .env and config.py are correctly setup
from config import web3_wallet, ocean
data_nft = ocean.create_data_nft(
name="NFTToken1",
symbol="NFT1",
from_wallet=web3_wallet,
# Optional parameters
token_uri="https://example.com",
template_index=1,
transferable=True,
owner=web3_wallet.address,
)
print(f"Created dataNFT. Its address is {data_nft.address}")
2022-08-02 14:52:51 +02:00
# replace the addresses here
fee_manager = "0x0000000000000000000000000000000000000000"
publish_market_order_fee_address = "0x0000000000000000000000000000000000000000"
publish_market_order_fee_token = "0x0000000000000000000000000000000000000000"
minter = web3_wallet.address
# replace the fee amount
publish_market_order_fee_amount = 0
2022-07-25 12:17:51 +02:00
2022-08-02 14:52:51 +02:00
datatoken = data_nft.create_datatoken(
name="Datatoken 1",
symbol="DT1",
datatoken_cap="100000",
from_wallet=web3_wallet,
# Ootional parameters below
template_index=1,
fee_manager=fee_manager,
publish_market_order_fee_token=publish_market_order_fee_token,
publish_market_order_fee_amount=publish_market_order_fee_amount,
minter=minter,
publish_market_order_fee_address=publish_market_order_fee_address,
)
2022-07-25 12:17:51 +02:00
print(f"Created datatoken. Its address is {datatoken.address}")
exchange_id = ocean.create_fixed_rate(
datatoken=datatoken,
base_token=ocean.OCEAN_token,
amount=ocean.to_wei(100),
from_wallet=web3_wallet,
)
print(f"Created fixed rate exchange with ID {exchange_id.hex()}")
2022-08-02 14:52:51 +02:00
2022-07-25 12:17:51 +02:00
```
{% endcode %}
2022-08-02 11:59:29 +02:00
#### Execute script
2022-07-25 12:17:51 +02:00
2022-08-02 11:59:29 +02:00
```
python create_datatoken_with_fre.py
```
2022-07-25 12:17:51 +02:00
{% endtab %}
{% endtabs %}