Mint LSP7 Token
In this guide you will mint some LSP7 Digital Asset tokens as an EOA contract owner.
Setupâ
The following code snippets require the installation of the following libraries:
- web3.js
- ethers.js
npm install web3 @lukso/lsp-smart-contracts
npm install ethers @lukso/lsp-smart-contracts
Imports and constantsâ
At this point, the LSP7 Mintable
contract is being prepared for the following interaction. You construct an instance of a contract, using its ABI and the contract address.
- web3.js
- ethers.js
web3.js
import LSP7Mintable from '@lukso/lsp-smart-contracts/artifacts/LSP7Mintable.json';
import Web3 from 'web3';
const myTokenAddress = '0x...';
const web3 = new Web3(window.lukso);
await web3.eth.requestAccounts();
const accounts = await web3.eth.getAccounts();
ethers.js
import LSP7Mintable from '@lukso/lsp-smart-contracts/artifacts/LSP7Mintable.json';
import { ethers } from 'ethers';
const myTokenAddress = '0x...';
await ethers.provider.send('eth_requestAccounts', []);
const signer = await ethers.getSigner();
Instantiate the contractsâ
After defining the core parameters of the LSP7 Mintable
contract, you are able to create an instance using its ABI and the contract address.
- web3.js
- ethers.js
web3.js
const myToken = new web3.eth.Contract(LSP7Mintable.abi, myTokenAddress);
ethers.js
const myToken = new ethers.Contract(myTokenAddress, LSP7Mintable.abi);
Send the transactionâ
Finally, you can send the transaction to mint some tokens.
warning
The sample contract of this guide only allows the smart contract owner to mint assets. Custom LSP7 implementations might implement different permission sets.
- web3.js
- ethers.js
web3.js
// mint 1 token
const amount = web3.utils.toWei('1', 'ether');
const mintTxn = await myToken.methods
.mint(
accounts[0], // recipient address
amount, // token amount
true, // force parameter
'0x', // additional data
)
.send({ from: accounts[0] });
console.log(mintTxn);
// Waiting 10sec to make sure the minting transaction has been processed
const balance = await myToken.methods.balanceOf(accounts[0]);
console.log('ðĶ Balance: ', balance.toString());
ethers.js
// mint 1 token
const amount = ethers.parseUnits('1', 'ether');
const mintTxn = await myToken.mint(
signer.address, // recipient address
amount, // token amount
true, // force parameter
'0x', // additional data
);
console.log(mintTxn);
// Waiting 10sec to make sure the minting transaction has been processed
const balance = await myToken.balanceOf(signer.address);
console.log('ðĶ Balance: ', balance.toString());