Web3js

幣安智能鏈錢包使用 web3modal 打開

  • August 24, 2021

Web3modal 在 dapp 中提供乙太坊錢包連接。我想連接幣安智能鏈錢包擴展。我認為可以為每個錢包擴展編輯 providerOptions。誰能給我詳細的回答我的問題?謝謝

下面的一段程式碼是我在我開發的 dapp 中使用的摘錄。

let providerOptions = {
 "custom-binancechainwallet": {
   display: {
     logo: "../../assets/img/binance-logo.svg",
     name: "Binance Chain Wallet",
     description: "Connect to your Binance Chain Wallet"
   },
   package: true,
   connector: async () => {
     let provider = null;
     if (typeof window.BinanceChain !== 'undefined') {
       provider = window.BinanceChain;
       try {
         await provider.request({ method: 'eth_requestAccounts' })
       } catch (error) {
         throw new Error("User Rejected");
       }
     } else {
       throw new Error("No Binance Chain Wallet found");
     }
     return provider;
   }
 }
};

let web3Modal = new Web3Modal({
 cacheProvider: true,
 providerOptions,
 disableInjectedProvider: false
});

引用自:https://ethereum.stackexchange.com/questions/97923