Skip to content

alchemyplatform/polygon-smart-contract-tutorial

Repository files navigation

How to Code, Deploy, and Interact with a Polygon (MATIC) Smart Contract

Follow the full written tutorial here.

Follow the full video tutorial here.

Quickstart

  1. npm install
  2. Rename .env-example to .env, and populate the variable values.
    1. Grab API_URL from www.alchemy.com by setting up a Polygon Mumbai testnet app.
    2. For PRIVATE_KEY, use your Ethereum wallet address's corresponding private key.
    3. You can leave CONTRACT_ADDRESS blank until you deploy with npx run scripts/sample-script.js, then grab the address where you deployed your contract to.
    4. ALCHEMY_API_KEY is very similar to API_URL except you can remove the http or ws prefix.
    5. MATIC_URL you can grab from www.alchemy.com but make sure your Alchemy app is a Polygon Mainnet app.
  3. run npx run scripts/sample-script.js --network mumbai to deploy your contract to Mumbai testnet
  4. run npx run scripts/greet.js --network mumbai to modify blockchain state by calling the Greet function on your smart contract.
  5. Repeat those steps with --network matic to deploy and interact on Polygon (MATIC) mainnet chain.