Market Cap: $2.8588T -5.21%
Volume(24h): $157.21B 50.24%
Fear & Greed Index:

38 - Fear

  • Market Cap: $2.8588T -5.21%
  • Volume(24h): $157.21B 50.24%
  • Fear & Greed Index:
  • Market Cap: $2.8588T -5.21%
Cryptos
Topics
Cryptospedia
News
CryptosTopics
Videos
Top Cryptospedia

Select Language

Select Language

Select Currency

Cryptos
Topics
Cryptospedia
News
CryptosTopics
Videos

How to Develop and Deploy a Contract on Polygon?

Set up Node.js, Hardhat, and Polygon Mumbai; write an ERC-20 contract with OpenZeppelin, test locally, deploy to Mumbai, then verify on Polygonscan.

Jan 19, 2026 at 04:59 pm

Setting Up the Development Environment

1. Install Node.js and npm to manage dependencies and run local scripts.

  1. Initialize a new project with npm init and install Hardhat as the primary development framework.
  2. Configure Hardhat to support Polygon Mumbai testnet by adding network details including RPC URL, chain ID, and private key in hardhat.config.ts.
  3. Add @nomicfoundation/hardhat-toolbox for built-in testing utilities and Ethers.js integration.
  4. Create a contracts directory and place Solidity files there, ensuring compatibility with Solidity version 0.8.19 or higher.

Writing a Simple ERC-20 Token Contract

1. Import OpenZeppelin’s ERC-20 implementation using @openzeppelin/contracts/token/ERC-20/ERC20.sol.

  1. Define a custom contract inheriting from ERC20 and set name, symbol, and initial supply in the constructor.
  2. Enforce access control by integrating Ownable to restrict minting or pausing functions to the deployer.
  3. Add a mint function that only the owner can call, increasing total supply and assigning tokens to a specified address.
  4. Include a burn function allowing token holders to destroy their own balance, reducing total supply accordingly.

Compiling and Testing Locally

1. Run npx hardhat compile to generate ABI and bytecode for deployment.

  1. Write tests in TypeScript using ethers.js and chai assertions inside the test directory.
  2. Deploy the contract to Hardhat Network using a script that retrieves signer, deploys instance, and verifies state changes.
  3. Execute npx hardhat test to validate transfer logic, mint permissions, and event emissions.
  4. Confirm all test cases pass without reverts or unexpected behavior before proceeding to external networks.

Deploying to Polygon Mumbai Testnet

1. Obtain MATIC tokens from the Mumbai faucet to cover gas fees during deployment.

  1. Use a wallet like MetaMask configured for Mumbai and export its private key securely.
  2. Create a deployment script referencing the network configuration and passing arguments such as initial supply and owner address.
  3. Execute npx hardhat run scripts/deploy.ts --network mumbai to initiate on-chain transaction.
  4. Wait for confirmation and record the deployed contract address from the console output for verification and interaction.

Verifying and Interacting with the Deployed Contract

1. Submit source code to Polygonscan via the “Verify and Publish” option under the contract page, providing compiler version and optimization settings.

  1. Use the verified contract interface on Polygonscan to read state variables like totalSupply or balanceOf.
  2. Interact directly through the “Write Contract” tab after connecting MetaMask and approving transactions.
  3. Call transfer functions to move tokens between addresses and confirm events appear in transaction logs.
  4. Query events like Transfer and Approval using ethers.js in a frontend or script to monitor real-time activity.

Frequently Asked Questions

Q: Can I deploy the same contract on Polygon Mainnet without modifying the code?A: Yes, provided the Solidity version, libraries, and external dependencies remain unchanged. Only the network configuration and RPC endpoint need updating.

Q: Why does my deployment fail with “insufficient funds” on Mumbai?A: This occurs when the deploying account holds zero or insufficient MATIC. Ensure you request tokens from the official Mumbai faucet and wait for confirmations.

Q: Is it mandatory to verify the contract on Polygonscan?A: Verification is not required for functionality but essential for transparency, auditability, and user trust—especially when exposing contracts to third parties.

Q: How do I handle gas estimation errors during deployment?A: Increase the gas limit in your Hardhat network configuration or manually specify gas values in the deploy script. Also check current network congestion levels on Polygonscan.

Disclaimer:info@kdj.com

The information provided is not trading advice. kdj.com does not assume any responsibility for any investments made based on the information provided in this article. Cryptocurrencies are highly volatile and it is highly recommended that you invest with caution after thorough research!

If you believe that the content used on this website infringes your copyright, please contact us immediately (info@kdj.com) and we will delete it promptly.

Related knowledge

See all articles

User not found or password invalid

Your input is correct