A fully tested ERC20 token smart contract built with Hardhat, supporting multi-network deployment on Ethereum and BNB Chain. Includes standard ERC20 features, ownership control, and scripts for deployment, verification, and testing.
Features:
- Standard ERC20 (OpenZeppelin): transfer, approve, allowance, transferFrom, balanceOf
- Ownable: transferOwnership, renounceOwnership
- Fixed supply minted once in the constructor; no mint/burn/pause after deployment
- No custom
increaseAllowanceordecreaseAllowancehelpers - Multi-network deploy (Ethereum + BSC)
• Node.js LTS (v18 or v20 recommended) • npm (comes with Node.js)
Check versions:
node -v
npm -v| Path | Purpose |
|---|---|
| contracts/MyERC20.sol | ERC20 token contract (OpenZeppelin ERC20 + Ownable) |
| scripts/deploy.js | Deployment script; deploys MyERC20 and prints a ready-to-run verify command |
| test/test.js | Mocha/Chai tests: deployment, transfers, approve/transferFrom, edge cases |
| hardhat.config.js | Hardhat config: networks (Hardhat, Sepolia, Mainnet, BSC Testnet, BSC Mainnet), Solidity 0.8.30, optimizer, Etherscan |
| package.json | Project metadata and dependency list |
| package-lock.json | Locked dependency versions for reproducible installs |
| .env.example | Template for required environment variables |
| .env | Local env vars (private key, RPC URLs, API keys). Not committed; copy from .env.example |
| .gitignore | Ignores node_modules , .env , cache , artifacts , coverage, etc. |
All dependencies are declared in package.json . package-lock.json pins exact versions so everyone gets the same dependency tree.
| Package | Type | Purpose |
|---|---|---|
| @openzeppelin/contracts | dependency | ERC20 and Ownable implementations used by MyERC20.sol |
| hardhat | devDependency | Build and test framework |
| @nomicfoundation/hardhat-toolbox | devDependency | Ethers v6, Chai matchers, other Hardhat plugins |
| dotenv | devDependency | Loads .env variables into process.env |
| hardhat-gas-reporter | devDependency | Gas usage report during test execution |
You do not install these individually. A single install step installs everything.
git clone <your-repo-url> MyERC20-Token
cd MyERC20-Tokennpm installThis installs both dependencies and devDependencies from package.json .
For reproducible installs (recommended for CI):
npm ciCopy the example file and fill in your values:
cp .env.example .env| Variable | Required | Description |
|---|---|---|
| PRIVATE_KEY | Yes | Deployer wallet private key (include the 0x prefix) |
| ETH_SEPOLIA_RPC_URL | Yes* | Ethereum Sepolia RPC URL |
| ETH_MAINNET_RPC_URL | Optional | Ethereum Mainnet RPC URL |
| BSC_TESTNET_RPC_URL | Yes* | BSC Testnet RPC URL |
| BSC_MAINNET_RPC_URL | Optional | BSC Mainnet RPC URL |
| ETHERSCAN_API_KEY | Optional | Etherscan API key for Ethereum contract verification |
| BSCSCAN_API_KEY | Optional | BSCScan API key for BSC contract verification |
*Required only for the network you plan to deploy to.
See .env.example for placeholder values.
npx hardhat compileArtifacts will be generated in:
artifacts/ cache/
Run the full test suite:
npx hardhat testTests are located in:
test/test.js
They cover:
• deployment • token transfers • approve / transferFrom • supply invariants
hardhat-gas-reporter is already enabled in hardhat.config.js . Run:
npx hardhat testGas usage is printed automatically after the test run.
Deploy to Ethereum Sepolia:
npx hardhat run scripts/deploy.js --network sepoliaDeploy to Ethereum Mainnet:
npx hardhat run scripts/deploy.js --network mainnetDeploy to BSC Testnet:
npx hardhat run scripts/deploy.js --network bscTestnetDeploy to BSC Mainnet:
npx hardhat run scripts/deploy.js --network bscStart a node:
npx hardhat nodeThen deploy in another terminal:
npx hardhat run scripts/deploy.js --network localhostThe deploy script logs:
• Network name + ChainId • Deployer wallet address and balance • Contract address • Deployment transaction hash • Token total supply • A ready-to-copy verify command, for example:
npx hardhat verify --network sepolia 0xYourDeployedContractAddressVerification publishes your source code so BSCScan can validate the bytecode and expose the Read / Write Contract interface.
Create an API key from:
BSCSCAN_API_KEY=YourApiKey
After deployment, the deploy script prints a verify command you can copy. Or run manually:
BSC Testnet:
npx hardhat verify --network bscTestnet DEPLOYED_CONTRACT_ADDRESSExample:
npx hardhat verify --network bscTestnet 0x1234567890abcde5nh5j45336mn65mn566m56bBSC Mainnet:
npx hardhat verify --network bsc DEPLOYED_CONTRACT_ADDRESSnpx hardhat verify --network sepolia DEPLOYED_CONTRACT_ADDRESSor
npx hardhat verify --network mainnet DEPLOYED_CONTRACT_ADDRESSMyERC20 has no constructor arguments, so no extra parameters are needed.
• This contract uses widely used and audited OpenZeppelin implementations.
• The design is intentionally minimal:
- fixed supply
- no minting after deployment
- no pause
- no blacklist
- no transaction fees
- no custom allowance helpers (
increaseAllowance/decreaseAllowance)
• This project has not been formally audited by a third-party security firm.
For production deployments consider:
• professional smart contract audit • multisig ownership • hardware wallet deployment
• Smart Contract ( contracts/MyERC20.sol ): MIT • Project Repository: ISC (see package.json )
This project is provided for educational and reference purposes only.
The authors and contributors:
• do not provide financial advice • do not guarantee security or correctness • are not responsible for losses resulting from the use of this code
Use this software and any deployed contracts at your own risk.