2022-07-25 12:17:51 +02:00
# Mint datatoken
2022-08-02 11:59:29 +02:00
This tutorial will guide you to mint datatoken and send it to a receiver address. The tutorial assumes that you already have the address of the datatoken contract which is owned by you. 
2022-07-25 12:17:51 +02:00
#### Configuration
See [this ](configuration.md ) guide on defining a `.env` file and a configuration file
#### Create a script to mint datatokens
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-07-25 12:17:51 +02:00
{% tabs %}
{% tab title="ocean.js" %}
{% code title="mint_datatoken.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);
// Change this
const datatokenAddress = "0xD3542e5F56655fb818F9118CE219e1D10751BC82"
const receiverAddress = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"
2022-08-02 14:52:51 +02:00
// Create a function which will take `datatokenAddress` and `receiverAddress` as parameters
2022-07-25 12:17:51 +02:00
const mintDatatoken = async (datatokenAddress, receiverAddress) => {
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
2022-08-02 14:52:51 +02:00
// Create datatoken instance
2022-07-25 12:17:51 +02:00
const datatoken = new Datatoken(web3);
2022-08-02 14:52:51 +02:00
// Get current datatoken balance of receiver
2022-07-25 12:17:51 +02:00
let receiverBalance = await datatoken.balance(
datatokenAddress,
receiverAddress
);
console.log(`Receiver balance before mint: ${receiverBalance}`);
2022-08-02 14:52:51 +02:00
// Mint datatoken
2022-07-25 12:17:51 +02:00
await datatoken.mint(
datatokenAddress,
publisherAccount,
'1',
receiverAddress
);
2022-08-02 14:52:51 +02:00
// Get new datatoken balance of receiver
2022-07-25 12:17:51 +02:00
receiverBalance = await datatoken.balance(
datatokenAddress,
receiverAddress
);
console.log(`Receiver balance after mint: ${receiverBalance}`);
};
2022-08-02 14:52:51 +02:00
// Call mintDatatoken(...) function defined above
2022-07-25 12:17:51 +02:00
mintDatatoken(datatokenAddress, receiverAddress)
.then(() => {
process.exit((err) => {
console.error(err);
process.exit(1);
});
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
2022-08-02 11:59:29 +02:00
#### Execute script
```
node mint_datatoken.js
```
2022-07-25 12:17:51 +02:00
{% endtab %}
{% tab title="ocean.py" %}
{% code title="mint_datatoken.py" %}
```python
# Note: Ensure that .env and config.py are correctly setup
from config import web3_wallet, ocean
# Change this
datatoken_address = "0xD3542e5F56655fb818F9118CE219e1D10751BC82"
receiver_address = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"
datatoken = ocean.get_datatoken(datatoken_address)
print(f"Balance before mint: {datatoken.balanceOf(receiver_address)}")
2022-08-02 14:52:51 +02:00
# Mint datatokens
2022-07-25 12:17:51 +02:00
datatoken.mint(
account_address=receiver_address,
value=ocean.to_wei("1"),
from_wallet=web3_wallet,
)
print(f"Balance after mint: {datatoken.balanceOf(receiver_address)}")
nt_d
```
{% endcode %}
2022-08-02 11:59:29 +02:00
#### Execute script
```
python mint_datatoken.py
```
2022-07-25 12:17:51 +02:00
{% endtab %}
{% endtabs %}