GithubHelp home page GithubHelp logo

alchemyplatform / polygon-smart-contract-tutorial Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 7.0 377 KB

A guide for coding and deploying a basic Polygon (MATIC) smart contract!

Home Page: https://docs.alchemy.com/alchemy/tutorials/how-to-code-and-deploy-a-polygon-smart-contract

Solidity 13.74% JavaScript 86.26%
alchemy ethersjs hardhat matic

polygon-smart-contract-tutorial's Introduction

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.

polygon-smart-contract-tutorial's People

Contributors

thatguyintech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

polygon-smart-contract-tutorial's Issues

Failed on matic mainnet with "error: Error: transaction underpriced"

Hi,
thanks for the great tutorial! I tried it on polygon mainnet directly (instead of testnet).
Deploying the contract worked like a charm, I see my contract on the blockchain.

However, setting a new greeting with

npx hardhat run scripts/greet.js

always fails with "error: Error: transaction underpriced". How do I set the gasPrice in

const setTx1 = await Greeter.setGreeting("web3 is ngmi!")

Maybe related, I saw in artifacts/contracts/Greeter.sol/Greeter.json that the function setGreeting appears to be "nonpayable", but shouldn't it be actually be a payble (state-changing) function?

{
      "inputs": [
        {
          "internalType": "string",
          "name": "_greeting",
          "type": "string"
        }
      ],
      "name": "setGreeting",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    }


Retrieve the greeting in scripts/greet.js with console.log("before: " + await Greeter.greet()); does work without problems.

Can you please help me?

Thanks a lot!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.