Skip to content

Minting and Burning Tokens (Smart Contract) #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
11 changes: 11 additions & 0 deletions minting and burning/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Creating a basic Contract with deployment and test cases of Minting and Burning Token s

1. Admin can assign a Minter Role and Burner Role and revert back their roles too
2.Minter can Mint tokens required
3. Burner can Burn tokens
4. Transfer of token can be made and it will give Admin a gas fee on every 1 million transfer of token

Created using simpler framework Hardhat ...while u can also run and check on Replit

for Hardhat (install)
npx hardhat
42 changes: 42 additions & 0 deletions minting and burning/Remix/MyToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/access/AccessControl.sol";

contract MyToken is ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER");
bytes32 public constant BURNER_ROLE = keccak256("BURNER");

address public admin;

constructor() ERC20("MyCustomToken", "MCT") {
admin = msg.sender;
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

function mint(address to, uint256 amount) external onlyRole(MINTER_ROLE) {
_mint(to, amount);
}

function burn(address from, uint256 amount) external onlyRole(BURNER_ROLE) {
_burn(from, amount);
}

function _transfer(address from, address to, uint256 value) internal virtual override {
if (totalSupply() > 1_000_000 * 10 ** decimals()) {
uint256 fee = (value * 1) / 100;
super._transfer(from, admin, fee);
value -= fee;
}
super._transfer(from, to, value);
}

function assignMinter(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
_grantRole(MINTER_ROLE, account);
}

function assignBurner(address account) external onlyRole(DEFAULT_ADMIN_ROLE) {
_grantRole(BURNER_ROLE, account);
}
}