标签:chainId name symbol js error 区块 decimals ethers blockBrowseUrl
<div @click="add">add</div>
import { BigNumber } from "ethers";
const obj = {
chainId: '97',
blockBrowseUrl: 'https://testnet.bscscan.com',
name: 'Binance Smart Chain Testnet',
blockJsonRpcUrl: 'https://endpoints.omniatech.io/v1/bsc/testnet/public',
symbol: 'tBNB',
decimals: 18,
}
const {
chainId,
blockBrowseUrl,
name,
blockJsonRpcUrl,
symbol,
decimals,
} = obj;
const add = async () => {
try {
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: BigNumber.from(chainId).toHexString().replace("0x0", "0x"),
chainName: name,
nativeCurrency: {
name: symbol,
symbol: symbol,
decimals: decimals,
},
rpcUrls: [blockJsonRpcUrl],
blockExplorerUrls: [blockBrowseUrl],
},
],
});
} catch (error) {
console.log("[ error ] >", error);
}
}
标签:chainId,
name,
symbol,
js,
error,
区块,
decimals,
ethers,
blockBrowseUrl
From: https://www.cnblogs.com/eternityyl/p/17116837.html