[TIL] Part4 - DAY67 Project - typescript(메타마스크SDK)

박동우·2023년 6월 29일

블록체인 스쿨 3기

목록 보기
63/72

[TIL] 2023-06-29 DAY67


Project

GIT 주소
https://github.com/dowoo303/SOLIDITY
https://github.com/dowoo303/hardhat


오늘 배운것들

  1. 어제만든 mint NFT, sale NFT 컨트랙트 ts에 연결하여 사용해보기(메마SDK이용)

각종 팁

회고




💻 Solidity 코딩

✅ dapp

SDK를 이용하면 웹과 모바일 모두 대응이 가능하다.
https://docs.metamask.io/wallet/how-to/use-sdk/
npm i @metamask/sdk : 설치 후 사용

layout 나누기

민팅페이지와 세일페이지 만들어보기.

🟥 코드

const onClickLogIn = async () => {
    try {
      const accounts = await ethereum?.request({
        method: "eth_requestAccounts",
      });

      setAccount(accounts[0]);

      // 네트워크 스위칭 제안 기능
      if (parseInt(ethereum?.networkVersion) !== MUMBAI_CHAIN_ID) {
        await ethereum?.request({
          method: "wallet_addEthereumChain",
          params: [
            {
              chainName: "Mumbai",
              chainId: web3.utils.numberToHex(MUMBAI_CHAIN_ID),
              nativeCurrency: { name: "MATIC", decimals: 18, symbol: "MATIC" },
              rpcUrls: ["https://rpc-mumbai.maticvigil.com"],
            },
          ],
        });
      }
    } catch (error) {
      console.error(error);
    }
  };


profile
HELLO!

0개의 댓글