Create an LSP7 Digital Asset (Token)
This guide will teach you how to create an LSP7 Digital Asset contract.
Deploy an LSP7 Digital Asset contract
We will use a specific implementation of LSP7, called LSP7Mintable
. It allows the contract deployer to mint new tokens.
Make sure you have the following dependencies installed:
- Either
web3.js
orethers.js
@lukso/lsp-smart-contracts
- web3.js
- ethers.js
Install the dependencies
npm install web3 @lukso/lsp-smart-contracts
Install the dependencies
npm install ethers @lukso/lsp-smart-contracts
Step 1 - Setup imports and constants
At this point you will need a private key in order to deploy an LSP7Mintable
contract.
We will import LSP7Mintable
in order to get the ABI and bytecode of the contract that will be deployed.
- web3.js
- ethers.js
import LSP7Mintable from '@lukso/lsp-smart-contracts/artifacts/LSP7Mintable.json';
import Web3 from 'web3';
const web3 = new Web3('https://rpc.testnet.lukso.network');
// initialize your EOA
const privateKey = '0x...';
const account = web3.eth.accounts.wallet.add(privateKey);
import LSP7Mintable from '@lukso/lsp-smart-contracts/artifacts/LSP7Mintable.json';
import { ethers } from 'ethers';
const provider = new ethers.providers.JsonRpcProvider(
'https://rpc.testnet.lukso.network',
);
// setup your EOA
const privateKey = '0x...';
const myEOA = new ethers.Wallet(privateKey).connect(provider);
Step 2 - Instantiate contracts
At this point, the LPS7Mintable
contract is being prepared for deployment.
- web3.js
- ethers.js
const myToken = new web3.eth.Contract(LSP7Mintable.abi, {
gas: 5_000_000,
gasPrice: '1000000000',
});
const lsp7Factory = new ethers.ContractFactory(
LSP7Mintable.abi,
LSP7Mintable.bytecode,
);
Step 3 - Send transaction
Finally, deploy the contract.
- web3.js
- ethers.js
Deploy the LSP7 Digital Asset contract
await myToken.deploy({
data: LSP7Mintable.bytecode,
arguments: [
'My LSP7 Token', // token name
'LSP7', // token symbol
account.address, // new owner, who will mint later
false, // isNonDivisible = TRUE, means NOT divisible, decimals = 0)
],
})
.send({ from: account.address });
Deploy the LSP7 Digital Asset contract
const myToken = await lsp7Factory.connect(myEOA).deploy(
'My LSP7 Token', // token name
'LSP7', // token symbol
myEOA.address, // new owner, who will mint later
false, // isNonDivisible = TRUE, means NOT divisible, decimals = 0)
);
Final code
- web3.js
- ethers.js
import LSP7Mintable from '@lukso/lsp-smart-contracts/artifacts/LSP7Mintable.json';
import Web3 from 'web3';
const web3 = new Web3('https://rpc.testnet.lukso.network');
// initialize your EOA
const privateKey = '0x...';
const account = web3.eth.accounts.wallet.add(privateKey);
// create a contract instance
const myToken = new web3.eth.Contract(LSP7Mintable.abi, {
gas: 5_000_000,
gasPrice: '1000000000',
});
// deploy the token contract
await myToken.deploy({
data: LSP7Mintable.bytecode,
arguments: [
'My LSP7 Token', // token name
'LSP7', // token symbol
account.address, // new owner, who will mint later
false, // isNonDivisible = TRUE, means NOT divisible, decimals = 0)
],
})
.send({ from: account.address });
import LSP7Mintable from '@lukso/lsp-smart-contracts/artifacts/LSP7Mintable.json';
import { ethers } from 'ethers';
const provider = new ethers.providers.JsonRpcProvider('https://rpc.testnet.lukso.network');
// set up your EOA
const privateKey = '0x...';
const myEOA = new ethers.Wallet(privateKey).connect(provider);
// create an instance of the token contract
const lsp7Factory = new ethers.ContractFactory(
LSP7Mintable.abi,
LSP7Mintable.bytecode,
);
// deploy the token contract
const myToken = await lsp7Factory.connect(myEOA).deploy(
'My LSP7 Token', // token name
'LSP7', // token symbol
myEOA.address, // new owner, who will mint later
false, // isNonDivisible = TRUE, means NOT divisible, decimals = 0)
);