Created
March 18, 2024 21:20
-
-
Save Praiseike/d7e0eb962fe8adb8ef7d247cdde6fdf0 to your computer and use it in GitHub Desktop.
simple solidity smart contract in typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| pragma solidity ^0.8.0; | |
| import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
| contract MyToken is ERC20 { | |
| address public owner; | |
| constructor(uint256 initialSupply) ERC20("MyToken", "MTK") { | |
| _mint(msg.sender, initialSupply); | |
| owner = msg.sender; | |
| } | |
| function transferOwnership(address newOwner) public { | |
| require(msg.sender == owner, "Only the owner can transfer ownership"); | |
| owner = newOwner; | |
| } | |
| function mint(uint256 amount) public { | |
| require(msg.sender == owner, "Only the owner can mint tokens"); | |
| _mint(owner, amount); | |
| } | |
| function burn(uint256 amount) public { | |
| _burn(msg.sender, amount); | |
| } | |
| function decimals() public view returns (uint8) { | |
| return 18; // Assuming 18 decimals for this example | |
| } | |
| function symbol() public view returns (string memory) { | |
| return "MTK"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment