DeveloperBreeze

Smart Contracts Programming Tutorials, Guides & Best Practices

Explore 7+ expertly crafted smart contracts tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Writing an ERC-20 Token Contract with OpenZeppelin

Tutorial August 22, 2024
solidity

     async function main() {
         const [deployer] = await ethers.getSigners();

         console.log("Deploying contracts with the account:", deployer.address);

         const MyToken = await ethers.getContractFactory("MyToken");
         const myToken = await MyToken.deploy("MyToken", "MTK", ethers.utils.parseUnits("1000000", 18));

         console.log("MyToken deployed to:", myToken.address);
     }

     main()
         .then(() => process.exit(0))
         .catch((error) => {
             console.error(error);
             process.exit(1);
         });
  • getSigners: Retrieves the list of accounts provided by the Ethereum node, with the first account used as the deployer.
  • getContractFactory: Gets the contract to deploy.
  • deploy: Deploys the contract with the specified parameters (name, symbol, and initial supply).
  • parseUnits: Converts the initial supply to the correct units, considering the token’s decimals.