Function Interface for Token Contract
Function: mint
Your contract should include the mint
function. Here is the signature:
This function creates new tokens and adds them to the total supply. The parameters are:
address to
: The address to receive the newly minted tokens.uint256 amount
: The amount of tokens to be minted and sent to the designated address.
Here is a brief implementation example of the mint
function using OpenZeppelin's ERC20 library:
The onlyMinter
modifier restricts access to the mint
function to authorized minters only, ensuring control over the creation of new tokens.
This mint
function is key to the effective operation of cross-chain transfers within our system. By minting tokens on the destination chain that correspond tokens burnt on the source chain, the mint
function ensures that total token supply remains consistent across all chains
Accessing the Minter Role
In order to use the mint
function, you will need to provide our relay contract with permission to pass the onlyMinter
check. This necessitates the inclusion of a function in your contract that enables the assignment of the minter role.
Possible options are:
Mapping for Minters: Use a mapping in your contract to track the minter access of addresses.
Grant Role Function: Use a function in your contract that allows a specific role, such as an owner or admin, to grant the minter role. This can be done using a role-based access control library like OpenZeppelin's Access Control library.
Function: burn
Your contract should also implement a burn
function for token destruction. We expect this function will burn/remove a certain amount of tokens. We currently support the two interfaces for burn function:
XYERC20 (V1)
This burn
function should destroy a specified amount of tokens from the msg.sender
's balance. The parameter is:
uint256 amount
: The number of tokens to be burnt or destroyed.
Here is a brief implementation of the burn
function using OpenZeppelin's ERC20 library:
In this example, the _burn
function, a part of OpenZeppelin's ERC20 library, is used to burn tokens. It deducts the amount
from msg.sender
's balance and reduces the total supply of tokens accordingly.
XYERC20 (V2)
This burn
function should destroy a specified amount of tokens from the account
's balance. The parameters are:
address account
: The address of the account from which the tokens will be burned.uint256 amount
: The number of tokens to be burnt or destroyed.
Make sure you add the onlyMinter
modifier or such access control function to protect this burn function, and you will need to provide our relay contract with permission to pass the onlyMinter
check as well.
The burn
function empowers your contract to maintain the integrity of the token's supply when tokens are sent across different blockchains.
Last updated