Skip to content

Develop, test and deploy Solidity contracts based on OpenZeppelin framework and Hardhat development environment. Deploy to Polygon blockchain.

Notifications You must be signed in to change notification settings

briangershon/openzeppelin-solidity-hardhat-playground

Repository files navigation

openzeppelin-solidity-hardhat-playground

Solidity tests

Develop, test and deploy Solidity contracts based on OpenZeppelin. Use Hardhat development environment. Deploy to Polygon.

Use as a starter template for new Solidity projects.

Initially based on the OpenZeppelin Learn tutorial.

Tested with Node v16.15 (LTS).

Added:

  • additional testing features
    • run tests locally (via npm test)
    • use Chai matchers from Waffle (instead of OpenZeppelin Test Helpers)
    • includes Github Action to run tests
  • solhint linter config (and then install plugin for your editor that supports solhint syntax highlighting)
  • format files with Prettier (npm run style)
  • configuration to deploy to Polygon Mumbai test network
  • turn on Solidity optimization (1000 means optimize for more high-frequency usage of contract). Compiler Options
  • add hardhat-etherscan for verifying contracts on PolygonScan (or Etherscan), which means uploading the source code so it's available for contract users to view/verify. For more info see hardhat-etherscan plugin.

Deploying

Deploy to Polygon Mumbai Testnet

  • copy .env.sample to .env
    • add your Ethereum node RPC URL, for example a url from Alchemy or another Ethereum node services.
    • add your wallet account's private key used for deploying, for example an account created via MetaMask.
    • to verify contract in a later step, create and add your ETHERSCAN_API_KEY by grabbing your key at https://polygonscan.com/myapikey
  • ensure your wallet account has some MATIC via https://faucet.polygon.technology/
  • deploy via npx hardhat run --network mumbai scripts/deploy.js
  • grab the resulting contract address that you just deployed, let's call that NEW_CONTRACT_ADDRESS_HERE
  • optionally, test manually via console -- see Playing with Contract below
  • upload source code so others can verify it on-chain via npx hardhat verify --network mumbai NEW_CONTRACT_ADDRESS_HERE
  • view contract (and/or call methods directly) in Polygonscan https://mumbai.polygonscan.com/, just look up NEW_CONTRACT_ADDRESS_HERE

Deploy to Polygon Mainnet

Use same instructions above for Polygon Mumbai testnet but use --network mainnet command option instead.

Playing with Contract

Interact with it via the console (npx hardhat console --network mumbai)

await ethers.provider.listAccounts();    // you should see your public wallet account (the match for your private key) listed

const Box = await ethers.getContractFactory('Box');
const box = await Box.attach('<contract address goes here>');
await box.store(42);
// you'll need to wait a bit until value is stored on the blockchain before retrieving in next step
await box.retrieve();   // you'll ultimately see `BigNumber { value: "42" }`

Example deploys

About

Develop, test and deploy Solidity contracts based on OpenZeppelin framework and Hardhat development environment. Deploy to Polygon blockchain.

Topics

Resources

Stars

Watchers

Forks