04월 20일 목요일
메타마스크와 프론트엔드 연결하기
const onClickAccount = async () => { try { const accounts = await window.ethereum.request({ method: "eth_requestAccounts", }); // console.log(accounts); setAccount(accounts[0]); } catch (error) { console.error(error); } };
window.ethereum 콘솔찍어보면 메타마스크 창이 나온다!
Web3
npm i web3
로 설치 후 import 후
const web3 = new Web3("https://rpc-mumbai.maticvigil.com");
로 선언해주고
web3.config.js 파일 생성 후
export const CONTRACT_ADDRESS = "";
export const CONTRACT_ABI = [];
넣어준 후
const contract = new web3.eth.Contract(CONTRACT_ABI, CONTRACT_ADDRESS);
정의하면 프론트엔드에서 블록체인 함수를 사용할 수 있다로 이해했음
읽기(조회)만 할때는 call함수 기록할 때는 send 함수
오늘 배운 것 :
각종 팁 :