diff --git a/minting and burning token (smart contract) b/minting and burning token (smart contract) new file mode 100644 index 00000000..e69de29b diff --git a/minting and burning/Readme.md b/minting and burning/Readme.md new file mode 100644 index 00000000..cc7d93c9 --- /dev/null +++ b/minting and burning/Readme.md @@ -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 \ No newline at end of file diff --git a/minting and burning/Remix/MyToken.sol b/minting and burning/Remix/MyToken.sol new file mode 100644 index 00000000..570e12c7 --- /dev/null +++ b/minting and burning/Remix/MyToken.sol @@ -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); + } +} \ No newline at end of file