Minting, Burning and Blacklisting Your XRC-20 Tokens in XDC Network

  • A coin operates on its own blockchain. By this definition, it is easy to point out that examples of coins are ETher and XDC. A coin also acts like money, where it can replace fiat currencies for payment purposes. Finally, a coin can be mined on the blockchain.
  • On the other hand, a token does not have its own blockchain. Instead, it runs on an existing blockchain, such as the XDC network. A token usually uses a smart contract to maintain records of who owns what. Unlike coins generally accepted for various services on the Blockchain, tokens are much more restrictive in their uses, and specific tokens are only accepted for specific services (think of the carnivals example).
  • A coin is essentially a digital version of money, while a token can represent more than just money; it may represent assets or deeds.
  • You can buy tokens with coins, but not the other way round.
  • totalSupply — returns the total token supply
  • balanceOf(address _owner) — returns the account balance of _owner
  • transfer(address _to, uint256 _value) — transfers _value to _to and fire the Transfer event. The function should revert if the _from account does not have enough tokens to spend
  • approve(address _spender, uint256 _value) — Allows _spender to withdraw from the account several times, up to the _value amount
  • transferFrom(address _from, address _to, uint256 _value) — transfers _value from _from to _to and fires the Transfer event. The function should revert unless the _from account has deliberately authorized the sender of the message via some mechanism
  • allowance(address _owner, address _spender) — returns the amount which the _spender is still allowed to withdraw from the _owner.
  • Blacklistupdate — Allows to block the users by entering the user address and entering the boot value as True and false. Once the address is blacklisted the blacklisted address will not be able to receive or send the funds
  • Mint — Allows the owner to mint the new tokens
  • Burn — Allows the owner to burn the existing tokens.
  • How to create your token on the XDC network
  • How to mint, burn and blacklist your token
// SPDX-License-Identifier: MITpragma solidity >=0.7.0 <0.8.0;import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.2.0-solc-0.7/contracts/token/ERC20/ERC20.sol";import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.2.0-solc-0.7/contracts/token/ERC20/ERC20Burnable.sol";import “https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.2.0-solc-0.7/contracts/access/Ownable.sol";contract Goldtoken is ERC20Burnable, Ownable {mapping(address => bool) _blacklist;event BlacklistUpdated(address indexed user, bool value);constructor()ERC20(“Gold Token”, “GLD”)Ownable(){// _owner = _msgSender();_mint(msg.sender, 10000000 * (10 ** uint256(decimals())));}function mint(address to, uint256 amount) public virtual onlyOwner {// require(_owner == _msgSender(), “Only owner is allowed to mint token.”);_mint(to, amount);}function blacklistUpdate(address user, bool value) public virtual onlyOwner {// require(_owner == _msgSender(), “Only owner is allowed to modify blacklist.”);_blacklist[user] = value;emit BlacklistUpdated(user, value);}function isBlackListed(address user) public view returns (bool) {return _blacklist[user];}function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20) {require (!isBlackListed(to), “Token transfer refused. Receiver is on blacklist”);require (!isBlackListed(from), “Token transfer refused. You are on blacklist”);super._beforeTokenTransfer(from, to, amount);}}
  • you imported the base ERC20.sol (ERC20) contract from OpenZeppelin
  • your token contract (Goldtoken) is inheriting from the ERC20 base contract with the blacklist functionalities
  • in the constructor of the contract, you (the contract owner) are minting 1000 tokens using the _mint() function (defined in the ERC20 contract). Internally, you will represent these 1000 tokens as 1000 x 1⁰¹⁸.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store