1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-02 00:05:35 +01:00
docs/building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md

127 lines
3.1 KiB
Markdown
Raw Normal View History

2022-07-25 12:17:51 +02:00
# Create Datatoken with fixed pricing
#### Configuration
See [this](configuration.md) guide on defining a `.env` file and a configuration file
#### Create a script to deploy dataNFT and datatoken with fixed pricing.
{% tabs %}
{% tab title="ocean.js" %}
{% code title="create_datatoken_with_fre.js" %}
```javascript
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 fixedPriceParams = {
fixedRateAddress: oceanConfig.fixedRateExchangeAddress,
baseTokenAddress: oceanConfig.oceanTokenAddress,
owner: publisherAccount,
marketFeeCollector: publisherAccount,
baseTokenDecimals: 18,
datatokenDecimals: 18,
fixedRate: '1',
marketFee: '0',
allowedConsumer: publisherAccount,
withMint: false
}
const result = await Factory.createNftErc20WithFixedRate(
publisherAccount,
nftParams,
erc20Params,
fixedPriceParams
);
const erc721Address = result.events.NFTCreated.returnValues[0];
const datatokenAddress = result.events.TokenCreated.returnValues[0];
return {
erc721Address,
datatokenAddress
};
};
createDataNFT()
.then(({ erc721Address, datatokenAddress }) => {
console.log(`DataNft address ${erc721Address}`);
console.log(`Datatoken address ${datatokenAddress}`);
process.exit(1);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
teatatokfreicreate_datatoken_with_fre.js
```
{% endcode %}
{% 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}")
datatoken = data_nft.create_datatoken("Datatoken 1", "DT1", from_wallet=web3_wallet)
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()}")
```
{% endcode %}
{% endtab %}
{% endtabs %}