ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [블록체인] verify and publish by hardhat (goerli, polygon mumbai)
    블록체인 2023. 1. 10. 10:40
    반응형

    하드햇 배포 뿐만 아니라 편하게 verify and publish 까지 할수있다.

     

    필요한거는 verify 하고자 하는곳의 apikey 그리고 @nomiclabs/hardhat-ethers 

    이거 두개 있으면 verify 까지 터미널에서 가능하다

     

    hardhat.config.js 에서 파일을 수정 해줄껀데

    require("@nomicfoundation/hardhat-toolbox");
    require("@nomiclabs/hardhat-ethers");
    require("dotenv").config();
    
    /** @type import('hardhat/config').HardhatUserConfig */
    const { PK, ETH_SCAN_KEY, GOERLI_NETWORK_URL, MUMBAI_NETWORK_URL, POLYGON_SCAN_KEY } = process.env;
    module.exports = {
    	solidity: "0.8.7",
    	etherscan: {
    		apiKey: { goerli: ETH_SCAN_KEY, polygonMumbai: POLYGON_SCAN_KEY },
    	},
    	networks: {
    		goerli: {
    			url: GOERLI_NETWORK_URL,
    			accounts: [PK],
    		},
    		polygonMumbai: {
    			url: MUMBAI_NETWORK_URL,
    			accounts: [PK],
    		},
    	},
    };

    networks 는 네이밍에 제약은 없는듯 하다 그냥 배포하고자 mumbai 이렇게 해도 상관없다.

    배포하는 명령어 할때 npx hardhat run --network mumbai(polygonMumbai) scripts/deploy.js

    이런식으로 명령어랑 일치만 시켜주면 된다.

    근데 verify 하려면 apiKey에 네트워크별로 키값을 지정해줘야 하는데 이때는 지정된 네트워크이름을 적용해줘야한다.

     

    지정된 네트워크 이름이 아니면 아래와같은 에러가 난다.

    Error in plugin @nomiclabs/hardhat-etherscan: You set an Etherscan API token for the network "polygonmumbai" but the plugin doesn't support it, or it's spelled incorrectly.
    
    To see the list of supported networks, run this command:
    
      npx hardhat verify --list-networks

    그래서  npx hardhat verify --list-networks 명령어로 리스트 확인해보면         
    ╟──────────────────────┼────────────╢
    ║ mainnet              │ 1          ║
    ╟──────────────────────┼────────────╢
    ╟──────────────────────┼────────────╢
    ║ optimisticGoerli     │ 420        ║
    ╟──────────────────────┼────────────╢
    ╟──────────────────────┼────────────╢
    ║ avalanche            │ 43114      ║
    ╟──────────────────────┼────────────╢
    ║ polygonMumbai        │ 80001      ║
    ╟──────────────────────┼────────────╢
    ║ arbitrumTestnet      │ 421611     ║
    ╟──────────────────────┼────────────╢

     

    이런식으로 리스트 확인할수있으니까 네이밍 맞춰서 키값지정해주면 된다.

     

    그리고 constructor 사용한 경우에는 나같은 경우에는 컨스트럭터에서 다른 컨트랙트 주소를 받아서 인스턴스화 해서 사용했는데

    npx hardhat verify --network polygonMumbai "verify 하려는 주소" "construnctor 에서 사용할 주소"

    이런식으로 넣으주면 된다.

     

    https://hardhat.org/hardhat-runner/plugins/nomiclabs-hardhat-etherscan#multiple-api-keys-and-alternative-block-explorers

     

    Hardhat | Ethereum development environment for professionals by Nomic Foundation

    Hardhat is an Ethereum development environment. Compile your contracts and run them on a development network. Get Solidity stack traces, console.log and more.

    hardhat.org

     

Designed by Tistory.