{"id":15065228,"url":"https://github.com/freitasgouvea/token-erc-20","last_synced_at":"2025-08-17T18:09:26.851Z","repository":{"id":39574604,"uuid":"268231125","full_name":"freitasgouvea/token-erc-20","owner":"freitasgouvea","description":"This is an example of implementation in solidity language of an ERC-20 standard Ethereum Token, mintable and burnable, with owner access permissions and pausable module.","archived":false,"fork":false,"pushed_at":"2024-12-09T09:40:33.000Z","size":4620,"stargazers_count":44,"open_issues_count":5,"forks_count":21,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-16T08:55:11.262Z","etag":null,"topics":["alchemy","burnable","erc20","ethereum","foundry","hardhat","hardhat-deploy","hardhat-ethscan","inheritance","mint","mintable","mocha","nodejs","pausable","polygon","smart-contracts","solidity","solidity-language","token","truffle"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/freitasgouvea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-31T07:32:01.000Z","updated_at":"2024-07-02T01:22:01.000Z","dependencies_parsed_at":"2024-04-23T03:28:49.133Z","dependency_job_id":"0a931a9a-3b99-4884-a757-88cfd75e240c","html_url":"https://github.com/freitasgouvea/token-erc-20","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/freitasgouvea/token-erc-20","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freitasgouvea%2Ftoken-erc-20","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freitasgouvea%2Ftoken-erc-20/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freitasgouvea%2Ftoken-erc-20/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freitasgouvea%2Ftoken-erc-20/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freitasgouvea","download_url":"https://codeload.github.com/freitasgouvea/token-erc-20/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freitasgouvea%2Ftoken-erc-20/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270885866,"owners_count":24662517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alchemy","burnable","erc20","ethereum","foundry","hardhat","hardhat-deploy","hardhat-ethscan","inheritance","mint","mintable","mocha","nodejs","pausable","polygon","smart-contracts","solidity","solidity-language","token","truffle"],"created_at":"2024-09-25T00:35:27.331Z","updated_at":"2025-08-17T18:09:26.829Z","avatar_url":"https://github.com/freitasgouvea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ERC-20 Token\n\nThis is an example in solidity language of an implementation of ERC-20 standard Ethereum Token, mintable and burnable, with owner access permissions and pausable module. \n\nIn this repository you can:\n\n- Learn an implementation of ERC-20 standard Ethereum Token in Solidity language\n- Deploy an ERC-20 in different networks using Hardhat, Truffle and Foundry\n- Run tests on ERC-20 smart contracts using Hardhat, Truffle and Foundry\n\n## Erc-20 implementation\n\nThis smart contract is an implementation of the ERC20 token standard in the Solidity programming language.\n\nERC-20 is a standard interface for tokens widely used standard for creating fungible tokens, which are tokens that are interchangeable and have a uniform value.\n\nMore Information about Solidity Language and ERC-20 Standard:\n\n- [Solidity](https://solidity.readthedocs.io/en/v0.8.4/): `v0.8.4`\n- [ERC-20](https://eips.ethereum.org/EIPS/eip-20)\n\nThis repository contains an [`ERC-20`](./contracts/ERC20.sol) smart contract implementetion that can be found in `./contracts` folder.\n\n### Erc-20 Methods\n\n#### Constructor\n\nThe [`constructor`](./contracts/ERC20.sol#L33) function sets `name`, `symbol`, `decimals` and `totalSupply` of the token.\n\n#### Balance\n\nThe view function [`balanceOf`](./contracts/ERC20.sol#L72) returns the account balance of an account `_owner`.\n \n#### Allowance\n\nThe view function [`allowance`](./contracts/ERC20.sol#L127) returns the amount which address `_spender` is allowed to spend from another account - `_owner`.\n\n#### Transfer and Transfer From\n\nThe method  [`transfer`](./contracts/ERC20.sol#L52) is called by `msg.sender` account and transfers `_value` amount of tokens to another address `_to`.\n\nThe method [`transferFrom`](./contracts/ERC20.sol#L102) allows one third account `msg.sender` transfers `_value` amount of tokens from other address `_from` to other address `_to`. The `_from` address needs to approve `msg.sender` spend the `_value` first.\n\nBoth methods fire the `Transfer` event.\n\n#### Approve\n\nThe method [`approve`](./contracts/ERC20.sol#L84) allows one account - `_spender` - to spend from another account - `msg.sender` - the `_amount`.\n \n#### Increase Approval and Decrease Approval\n \nThose methods are not a ERC-20 standard but can be used to manage the value of the account allowances.\n\nThe method [`increaseApproval`](./contracts/ERC20.sol#L140) allows another account - `_spender` - to spend from another account - `msg.sender` - adding to current allowance the `_addedValue` amount.\n\nThe method [`decreaseApproval`](./contracts/ERC20.sol#L157) reduces the value approved to `_spender` to spend from another account - `msg.sender` - subtracting the `_subtractedValue` from the current approval amount. If the `_subtractedValue` is bigger than current approval the value will reduce to 0.\n\n#### Mint, Burn and Burn From\n\nThose methods are not a ERC-20 standard but are commonly used to create and destroy tokens.\n\nThe [`mintTo`](./contracts/ERC20.sol#L180) function creates `_amount` tokens and assigns them to account `_to`, increasing the total supply. Only the smart contract owner can mint.\n\nThe [`burn`](./contracts/ERC20.sol#L199) function destroys `_amount` tokens from `msg.sender`, reducing the total supply.\n\nThe [`burnFrom`](./contracts/ERC20.sol#L218) function destroys `_amount` tokens from account `_from`, reducing the total supply. The `_from` address needs to approve the `msg.sender` address spend the `_amount` first.\n\nAll these methods fire the `Transfer` event.\n\n## Erc-20 Modules in this example\n\n#### Ownable\n\nThe [`ownable`](./contracts/ownership/Ownable.sol) smart contract module provides a basic access control mechanism, where there is an account - an owner - that has exclusive access to specific functions.\n\nThis module is used through inheritance.\n\nIt will make available the modifier `onlyOwner`, which can be applied to smart contract functions to restrict their use to the owner.\n\nBy default, the owner account will be the one that deploys the contract.\n\nThe owner address can be changed by smart contract owner with method `transferOwnership`.\n\n#### Pausable\n\nThe [`Pausable`](./contracts/lifecycle/Pausable.sol) module is smart contract which allows children to implement an emergency stop mechanism that can be triggered by an authorized account.\n\nThis module is used through inheritance.\n\nIt will make available the modifiers `whenNotPaused` and `whenPaused`, which can be applied to the functions of your contract.\n\nIn this example, only the owner account can trigger call `pause` and `unpause` methods.\n\n## Compile, test and deploy\n\nWith this repository you can compile, run tests and deploy the ERC-20 smart contract using Hardhat, Truffle or Foundry.\n\n- [Node.js](https://nodejs.org/download/release/latest-v12.x/): `12.0.0`\n- [Hardhat](https://hardhat.org/): `v2.9.9`\n- [Truffle](https://www.trufflesuite.com/truffle): `v5.5.19`\n- [Foundry](https://getfoundry.sh/)\n\n### Clone and Install\n\nClone or download this repository.\n\nGo to path and run on terminal:\n\n```sh\nnpm install\n```\n\nAfter, all dependencies will be downloaded.\n \n### Using Hardhat\n\n#### Compile contracts using Hardhat\n\n```sh\nnpx hardhat compile\n```\n\nAfter that, contract information \u0026mdash; including ABI \u0026mdash; will be available at the `./artifacts/contracts` directory.\n\n#### Run unit tests using Hardhat\n \nTo run tests on hardhat localhost, before run the tests start a local node:\n \n```sh\nnpx hardhat node\n```\n\nSo you can run tests which can be found in the test directory `./test`:\n\n```sh\nnpx hardhat --network localhost test\n```\n\nThe results of the tests and the detailed gas report will be show on screen.\n\n#### Deploy contracts with Hardhat and [Alchemy](https://www.alchemy.com/) as Provider\n\nCreate `.env` file on root with these variables:\n\n```\nPRIVATE_KEY= // Wallet private key\nALCHEMY_KEY= // Your Alchemy key from the choosen network\nTOKEN_NAME=\"Token Name\"\nTOKEN_SYMBOL=\"ERC\"\nTOKEN_DECIMALS=18\nTOKEN_TOTALSUPLY=0\nETHERSCAN_API_KEY= // Your Etherscan API key to verify contracts\nERC20_ADDRESS= // The address of deployed ERC20 to be verified\n```\n\nAvailable networks \u003cnetwork_name\u003e:\n \n- localhost\n- mainnet\n- goerli\n- sepolia\n- polygon\n- mumbai\n \nIt is important that the chosen wallet has selected network native tokens for the payment of gas.\n \nRun deploy script:\n\n```sh\nnpx hardhat run --network \u003cnetwork_name\u003e scripts/deploy.js\n```\n\nERC20 contract address will be shown on screen.\n \n#### Verify deployed ERC-20 with Hardhat\n\nUpdate `.env` file with these variables:\n\n```\nETHERSCAN_API_KEY= // Your Etherscan API key\nERC20_ADDRESS= // The address of deployed ERC20 to be verified\n```\n\nAvailable networks \u003cnetwork_name\u003e:\n \n- localhost\n- mainnet\n- goerli\n- sepolia\n \nRun verify script:\n\n```sh\nnpx hardhat run --network \u003cnetwork_name\u003e scripts/verify.js\n```\n\nAfter finishing, the link to the verified contract will be shown on screen.\n \n### Using Truffle\n\n#### Compile contracts using Truffle and Infura as Provider\n\n```sh\ntruffle compile\n```\n\nAfter running, contract information \u0026mdash; including ABI \u0026mdash; will be available at the `./build/contracts` directory.\n\n#### Run unit tests using Truffle\n \nTo run unit tests on local network development, you need install and run before run the tests [ganache](https://trufflesuite.com/ganache/)\n\nAfter initializing your local node, you can run tests which can be found in the test directory `./test`:\n\n```sh\ntruffle test\n```\n\nOr run tests within a specific file:\n\n```sh\ntruffle test \u003cfile_path\u003e\n```\n\n#### Run migration and deploy contracts with Truffle\n\nCreate `.env` file on root with:\n\n```\nPRIVATE_KEY= // Wallet private key\nINFURA_PROJECT_ID= // Your Infura Project Id\nTOKEN_NAME=\"Token Name\"\nTOKEN_SYMBOL=\"ERC\"\nTOKEN_DECIMALS=18\nTOKEN_TOTALSUPLY=0\n```\n \nIt is important that the chosen wallet has selected network native tokens for the payment of gas.\n\nAvailable networks \u003cnetwork_name\u003e:\n \n- localhost\n- ropsten\n- kovan\n- rinkeby\n- main\n- polygon\n- mumbai\n \nRun migrate command:\n\n```sh\ntruffle migrate --network \u003cnetwork_name\u003e\n```\n\nAfter migration, contract address and transactions will be shown on screen.\n\n### Using Foundry\n\n#### Install Foundry\n\nBefore run you need to get Foundry:\n\n```sh\ncurl -L https://foundry.paradigm.xyz | bash\n```\n\nAnd install:\n\n```sh\nfoundryup\n```\n\n#### Compile contracts using Foundry\n\n```sh\nforge build\n```\n\nAfter running, contract information \u0026mdash; including ABI \u0026mdash; will be available at the `./out` directory.\n\n#### Run tests using Foundry\n \nBefore run the tests, you need to update and registry the tests modules used by this repository that can be found in `./lib` folder:\n \n```sh\nforge update lib/forge-std\n```\n\nSo you can run tests which can be found in the file `./test-foundry/ERC20.t.sol`:\n\n```sh\nforge test\n```\n\nYou also can run tests and see all detailed traces:\n\n```sh\nforge test -vvvv\n```\n\nAnd if you want to debug a single test, and see the execution of EVM opcodes, use the debug flag and set the test function name:\n\n```sh\nforge test --debug functionToDebug\n```\n\nThe output of tests can be found in the folder `./out`.\n\n#### Deploy contracts with Foundry\n\nTo deploy using foundry you can run this command setting the constructor arguments (name, symbol, decimals and totalSupply) at `--constructor-args` flag and changing the `\u003cnetwork_rpc_url\u003e` of the target network and `\u003cdeployer_private_key\u003e`:\n\n```sh\nforge create --rpc-url \u003cnetwork_rpc_url\u003e \\\n  --constructor-args \"Token Name\" \"ERC\" 18 0 \\\n  --private-key \u003cdeployer_private_key\u003e src/ERC20.sol:ERC20 \\\n  --verify\n```\n\nThe hash of transaction and ERC20 contract address will be shown on screen.\n\n## Other Features\n\n### Run analysis using Mythril\n\nMythril is example of security analysis tool for EVM bytecode that detects security vulnerabilities in smart contracts:\n\n- [Mythril](https://github.com/ConsenSys/mythril)\n\nTo run a security analysis you first need to install the Mythril tool in your machine:\n\n```sh\npip3 install mythril\n```\n\nThen, you can run the `ERC20.sol` smart contract security scan:\n\n```sh\nmyth analyze contracts/ERC20.sol -o jsonv2\n```\n\nThe analysis may take several minutes to finish and the JSON output will be generated.\n\n#### Result of Mythril analysis of the smart contracts of this project\n\nNo issues was identified in this repository and the output of analysis was:\n\n```sh\n[{\"issues\": [], \"meta\": {\"mythril_execution_info\": {\"analysis_duration\": 3081529196262}}, \"sourceFormat\": \"text\", \"sourceList\": [\"#utility.yul\", \"contracts/ERC20.sol\", \"contracts/interfaces/IERC20.sol\", \"contracts/lifecycle/Pausable.sol\", \"contracts/ownership/Ownable.sol\"], \"sourceType\": \"solidity-file\"}]\n```\n\n### Run analysis using Slither\n\nSlither is a example of analysis tool that detects vulnerabilities and suggests optimizations in solidity smart contracts:\n\n- [Slither](https://github.com/crytic/slither)\n\nTo run Slither you first need to install the tool in your machine:\n\n```sh\npip3 install slither-analyzer\n```\n\nThen, you can run the scan in all smart contracts of this project:\n\n```sh\nslither .\n```\nThe output of analysis will be generated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreitasgouvea%2Ftoken-erc-20","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreitasgouvea%2Ftoken-erc-20","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreitasgouvea%2Ftoken-erc-20/lists"}