[Blockchain] Entering the world of web3 - the role of wallets

1. What is a web3 wallet

        The web3 wallet is a digital wallet used to store tokens, NFT and other digital assets. The encrypted wallet and web3 wallet we usually hear are the same thing, but they are called differently. The wallet is also a personal identity certificate, and users can log in to various web3 web applications and DAPPs through the wallet. Be sure to keep your mnemonic, whoever owns the mnemonic will have control of this wallet

2. Commonly used web3 hot wallets

        Many types of hot wallets on the market have similar functions. They all have the functions of sending digital assets, receiving digital assets, logging into web3 web applications and DAPPs as personal credentials, and communicating with smart contracts at the same time.

        The commonly used wallets are MetaMask and TrustWallet. MetaMask exists mainly on the web side as a browser plug-in. TrustWallet is mainly on the mobile side.

3. The role of the wallet in interacting with the contract

        First of all, we need to connect a concept provider. Provider (provider) is an abstract class used to connect to the Ethereum network. It provides a read-only form to access the blockchain network and obtain the state on the chain. Here ethers provides a provider by default, so we can perform some query operations on the smart contract without connecting to the wallet. For example: query domain name registration status, query domain name price, etc.

        The purpose of our connection to the wallet is also to obtain the RPC of the wallet, so we can ensure the normal operation of some query operations by writing hard RPC locally.

Our Dapp design principle is that the more convenient the better, unless necessary, do not perform strong verification of the connected wallet.

 


import { ethers } from "ethers";

// 方法1
const provider = ethers.getDefaultProvider()

// 方法2,将rpc地址替换即可
const providerRpc = new ethers.providers.JsonRpcProvider(`https://mainnet.infura.io/v3/`)

// RPC地址
{
    "ethMain": {
        "chainId": 1,
        "netInfo": {
            "chainName": "以太坊主网",
            "Nodes": "https://mainnet.infura.io/v3/",
            "BlockExplorerUrls": "https://etherscan.io"
        },
        "nativeCurrency": {
            "name": "ETH",
            "symbol": "ETH",
            "decimals": 18
        }
    },
    "bnbMain": {
        "chainId": 56,
        "netInfo": {
            "chainName": "BSC MAINNET",
            "Nodes": "https://bsc-dataseed.binance.org",
            "BlockExplorerUrls": ""
        },
        "nativeCurrency": {
            "name": "UNKNOWN",
            "symbol": "UNKNOWN",
            "decimals": 18
        }
    },
    "ethTest": {
        "chainId": 5,
        "netInfo": {
            "chainName": "ENS TEST",
            "Nodes": "https://goerli.infura.io/v3/",
            "BlockExplorerUrls": "https://etherscan.io"
        },
        "nativeCurrency": {
            "name": "ETH",
            "symbol": "ETH",
            "decimals": 18
        }
    },
    "bnbTest": {
        "chainId": 97,
        "netInfo": {
            "chainName": "BSC TEST",
            "Nodes": "https://bsc-testnet.public.blastapi.io",
            "BlockExplorerUrls": ""
        },
        "nativeCurrency": {
            "name": "tBNB",
            "symbol": "tBNB",
            "decimals": 18
        }
    },
    "doMain": {
        "chainId": 137,
        "netInfo": {
            "chainName": "BSC MAINNPolygon Mainnet",
            "Nodes": "https://polygon-mainnet.infura.io",
            "BlockExplorerUrls": "https://polygonscan.com/"
        },
        "nativeCurrency": {
            "name": "MATIC",
            "symbol": "MATIC",
            "decimals": 18
        }
    }
}

Guess you like

Origin blog.csdn.net/qq_23334071/article/details/130179558