πͺ Create a LSP7 Token
This guide will walk you through the process of creating and deploying a custom LSP7 Digital Asset and pre-mint a certain amount of tokens to the token owner. To build a smart contract using LSPs, you can inherit functionality from modular and standardized presets in the @lukso/lsp-smart-contracts
library. To learn more about the contract standards itself, please refer to the Contracts section of our documentation.
You can learn about the project setup and Hardhat workflow by checking the Getting Started section.
Create the Tokenβ
For our sample deployment of the LSP7 token, we will use the following presets:
LSP7Mintable
: allow the contractowner
to mint new tokens.LSP7Burnable
: allow any token holders to burn tokens.
You can then import them within your Solidity contract file:
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
import "@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol";
import "@lukso/lsp-smart-contracts/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol";
contract CustomToken is LSP7Mintable, LSP7Burnable {
// your custom token logic ...
}
After inheriting, the contract expects the mandatory parameters related to the imported standards. In case of LSP7
, you must define default token parameters in the constructor of the smart contract, that will be set during the deployment of the contract:
- the token name and symbol (inherited from LSP4)
- the address of the initial token owner
- the token type of the asset
- the divisibility of token units (specific to LSP7)
You can specify the parameters and the mint function as seen below.
// ...
contract CustomToken is LSP7Mintable, LSP7Burnable {
constructor(
string memory tokenName_,
string memory tokenSymbol_,
address tokenContractOwner_,
uint256 lsp4TokenType_,
bool isNonDivisible_
)
LSP7Mintable(
tokenName_,
tokenSymbol_,
tokenContractOwner_,
lsp4TokenType_,
isNonDivisible_
)
{
{
// your custom smart contract logic ...
mint(
msg.sender, // deployer will receive initial tokens
20_000 * 10 ** decimals(), // will mint 20k tokens
true, // force parameter
"" // optional transaction data
);
}
}
}
To adjust the parameters of the mint, please have a look at the related LSP7 function documentation. You can find the full documentation for LSP7 and other presets within the Technical ABI Reference.
Deploy the Tokenβ
Want to deploy token contracts from your π? Have a look at our Deploy Contracts from UP guide on how to deploy any contract using the Universal Profile Browser Extension!
import { ethers } from 'hardhat';
import * as dotenv from 'dotenv';
// Load environment variables
dotenv.config();
async function deployToken() {
// Signer used for deployment
const [deployer] = await ethers.getSigners();
console.log('Deploying contract with EOA: ', deployer.address);
// Deploy the contract with custom constructor parameters
const customToken = await ethers.deployContract('MyCustomToken', [
'My Custom Token', // token name
'MCT', // token symbol
deployer.address, // owner
0, // token type = TOKEN
false, // isNonDivisible?
]);
// Wait for the transaction to be included in a block
await customToken.waitForDeployment();
const customTokenAddress = await customToken.getAddress();
console.log('Token deployed at: ', customTokenAddress);
}
deployToken()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
If you have not yet setup the LUKSO networks and private keys in Hardhat, please check out the previous Getting Started guide for smart contract developers. If you set up the Hardhat configuration, you can execute the deployment script using the following command:
npx hardhat --network luksoTestnet run scripts/deployLSP7AsUP.ts
You can check the deployed token address on the Testnet Execution Explorer.
Verify the Tokenβ
In order to verify a contract, you have to create a file with all the constructor arguments that you've set during deployment. The parameters and the compiled contract code are then compared with the payload of the deployed contract. First, create the file with all constructor parameters:
module.exports = [
'My Custom Token', // token name
'MCT', // token symbol
'0x...', // deployer address
0, // token type
false, // divisibility
];
To verify the deployed token, you can use the blockscout API properties set up within the Getting Started section. If you configured the API, you will be able to run the verification by specifying the token address, paramter file, and network:
npx hardhat verify <myTokenAddress> --constructor-args ./verify/myCustomToken.ts --network luksoTestnet