This is a customizable ERC-20 token with additional features such as minting, burning, pausing, transaction fees, time-locking, and access control.
-
Minting– Allows tokens to be created by an authorized entity. -
Burning– Allows token holders to destroy their tokens. -
Pausing– Pauses all token transfers when needed. Access Control – Role-based access for minting, burning, and pausing. -
Governance– Includes role management for governance actions. -
Transaction Fees– Fee charged on every transfer. -
Time Locking– Tokens are locked for a specific time before they can be transferred. -
Tax Mechanism– Deducts a tax and sends it to a specified wallet on every transfer.
Prerequisites
- Node.js and npm installed on your system.
- Hardhat installed globally :
npm install --save-dev hardhat. - OpenZeppelin Contracts : This contract uses OpenZeppelin's ERC-20, AccessControl, and Pausable extensions.
git clone <repository-url> cd <repository-folder>
npm install
npx hardhat compile
npx hardhat
Create a new file deploy.js in the scripts folder with the following deployment script:
async function main() {
const MyCustomToken = await ethers.getContractFactory("MyCustomToken");
const token = await MyCustomToken.deploy("Custom Token", "CTKN", "0xYourFeeCollectorAddressHere");
await token.deployed();
console.log("Token deployed to:", token.address);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Then run:
npx hardhat run scripts/deploy.js --network localhost
Minting
Mint tokens to a specific address (only callable by minters):
token.mint("0xRecipientAddress", 1000);
Burning
Burn tokens from your account:
token.burn(1000);
Pausing
Pause the contract to stop transfers:
token.pause();
Time-Locking
Lock tokens for a specific address for a given period:
token.setLock("0xRecipientAddress", 3600); // 1 hour
Transaction Fees
A fee of 1% is deducted from every transfer and sent to the fee collector:
token.transfer("0xRecipientAddress", 100);
- Admin : Manages the roles, fees, and other settings.
- Minter : Allowed to mint new tokens.
- Pauser : Allowed to pause/unpause token transfers.
To grant roles:
token.grantRole(MINTER_ROLE, "0xMinterAddress");
token.grantRole(PAUSER_ROLE, "0xPauserAddress");
- Governance: Implement voting mechanisms for community-driven changes.
- Staking: Add staking functionality to earn rewards.