Skip to main content

Create a Fungible Token

MyToken.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {_LSP4_TOKEN_TYPE_TOKEN} from "@lukso/lsp4-contracts/contracts/LSP4Constants.sol";
import {LSP7DigitalAsset} from "@lukso/lsp7-contracts/contracts/LSP7DigitalAsset.sol";

contract MyToken is
LSP7DigitalAsset(
"MyToken", // token name
"MTKN", // token symbol
msg.sender, // contract owner
_LSP4_TOKEN_TYPE_TOKEN, // token type as uint256 (0 for Token, 1 for NFT, 2 for Collection)
false // make the token non divisible (true = 0 decimals, false = 18 decimals)
)
{
// Custom logic for your token...
}

LSP7 Tokens extensions

The @lukso/lsp7-contracts package includes token extensions (similarly to OpenZeppelin contracts) that can be added through inheritance. This enables to include specific functionalities for building your token.

Extension contractDescription
LSP7Burnable.solExposes a public burn(...) function that allows any token holder or operator to burn any amount of tokens.
LSP7CappedSupply.solEnable to specify a maximum supply on deployment / initialization, which caps the maximum amount of tokens that can be minted.

If your token contract uses the proxy pattern with initialize functions, use the InitAbstract version of these extension contracts (e.g: LSP7Burnable -> LSP7BurnableInitAbstract).

MyToken.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import { _LSP4_TOKEN_TYPE_TOKEN } from "@lukso/lsp4-contracts/contracts/LSP4Constants.sol";
import { LSP7DigitalAsset } from "@lukso/lsp7-contracts/contracts/LSP7DigitalAsset.sol";

// extensions
import { LSP7Burnable } from "@lukso/lsp7-contracts/contracts/extensions/LSP7Burnable.sol";
import { LSP7CappedSupply } from "@lukso/lsp7-contracts/contracts/extensions/LSP7CappedSupply.sol";

contract MyToken is
LSP7DigitalAsset(
"MyToken", // token name
"MTKN", // token symbol
msg.sender, // contract owner
_LSP4_TOKEN_TYPE_TOKEN, // token type as uint256 (0 for Token, 1 for NFT, 2 for Collection)
false // make the token non divisible (true = 0 decimals, false = 18 decimals)
),
LSP7Burnable,
LSP7CappedSupply(42_000_000 * 10 ** super.decimals())
{
function _mint(
address to,
uint256 amount,
bool force,
bytes memory data
)
internal
virtual
override(LSP7CappedSupply, LSP7DigitalAsset)
{
LSP7CappedSupply._mint(to, amount, force, data);
}

// Custom logic for your token...
}