[TIL] 2023-06-19

Melon Coder·2023년 6월 19일
0

TIL

목록 보기
50/50
post-thumbnail

Today I Learned


[hardhat]

오늘은 hardhat으로 컨트랙트를 배포하고 그 컨트랙트를 검증(verify)하는 작업을 해보았다.


verifying smart contracts

스마트 컨트랙트 검증은 스마트 컨트랙트의 소스 코드를 on-chain 바이트 코드에 일치시키는 과정이다.
이 과정을 통해 배포된 소스 코드가 게약 주소에서 실행되었던 소스 코드와 동일한지 확인할 수 있기 때문에 신뢰를 가질 수 있다.

verifying with a hardhat

  1. npm init: npm 시작
  2. npm i --save -dev hardhat: hardhat 설치
  3. npx hardhat: hardhat 시작
  4. npx hardhat compile: hardhat으로 컨트랙트 컴파일
  5. npx hardhat run --network "network" scripts/deploys.js: 컨트랙트 배포
  6. npx hardhat verify --network "network" "contract address": contract address를 넣고 verifying
  • hardhat.config.js에 개인키, 이더스캔 API, 블록체인 네트워크의 RPC-URL 필요함.
  • 배포하려는 컨트랙트에 constructor를 필요로 한다면 scripts 폴더의 deploy파일에서 .deploy(constructor 인풋값)을 꼭 해줘야 오류가 안난다.
  • verify하는 명령어에도 ca 뒤에 constructor 인풋값을 넣어줘야 verifying이 오류없이 되는 것을 확인할 수 있다.

이미지 자료 출처: https://blog.tenderly.co/guide-to-smart-contract-verification-methods/

0개의 댓글