Building Your Own Token as a Side Hustle: How to Create Your Token Step By Step Guide

By akohad Jan24,2023

[ad_1]

Photo by Traxer on Unsplash
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
contract ArdaG is ERC20 {
constructor() public {
_mint(msg.sender, 1000000000);
}
}
  • A function to allow the owner of the contract to mint new tokens:
address public owner;
constructor() public {
owner = msg.sender;
_mint(msg.sender, 1000000000);
}
function mint(uint256 _amount) public {
require(msg.sender == owner, "Only the owner can mint new tokens.");
_mint(msg.sender, _amount);
}
  • A function to allow the owner of the contract to burn tokens:
function burn(uint256 _amount) public {
require(msg.sender == owner, "Only the owner can burn tokens.");
_burn(msg.sender, _amount);
}
  • A function to allow the owner of the contract to pause and unpause the token transfers:
bool public paused;
function pause() public {
require(msg.sender == owner, "Only the owner can pause token transfers.");
paused = true;
}
function unpause() public {
require(msg.sender == owner, "Only the owner can unpause token transfers.");
paused = false;
}
  • Modify the transfer() function to check if the token transfers are paused:
function transfer(address _to, uint256 _value) public returns (bool) {
require(!paused, "Token transfers are paused.");
require(_to != address(0), "Invalid address.");
require(_value <= balanceOf(msg.sender), "Insufficient balance.");
_transfer(msg.sender, _to, _value);
emit Transfer(msg.sender, _to, _value);
return true;
}

New to trading? Try crypto trading bots or copy trading on best crypto exchanges

[ad_2]

Source link

By akohad

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *