W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
?WalletConnect
?讓您可以通過二維碼、移動錢包和桌面錢包進(jìn)行連接。 您可以在 WalletConnect 文檔中查看更多信息。
根據(jù)moralis 導(dǎo)入項目的方式添加提供程序腳本 - ?CDN
?、?npm
?或 ?yarn
?。
<script src="https://github.com/WalletConnect/walletconnect-monorepo/releases/download/1.7.1/web3-provider.min.js" rel="external nofollow" ></script>
npm install @walletconnect/web3-provider
yarn add @walletconnect/web3-provider
確保檢查您是否使用最新的穩(wěn)定版本的 ?
WalletConnect web3-provider
?,并相應(yīng)地更新版本。 在 Github 上查看他們的最新版本
調(diào)用身份驗證函數(shù),但帶有?provider
?選項,可以選擇使用?JS
?或者?React
?:
const user = await Moralis.authenticate({ provider: "walletconnect" })
import { useMoralis } from "react-moralis";
function App() {
const { authenticate, isAuthenticated, user } = useMoralis();
const login = async () => {
if (!isAuthenticated) {
await authenticate({ provider: "walletconnect" })
.then(function (user) {
console.log(user!.get("ethAddress"));
})
.catch(function (error) {
console.log(error);
});
}
}
}
指定 ?WalletConnect
?默認(rèn)使用的鏈 ID。 您可以通過提供 ?chainId
?作為額外選項來做到這一點,可以選擇使用?JS
?或者?React
?:
const user = await Moralis.authenticate({ provider: "walletconnect", chainId: 56 })
import { useMoralis } from "react-moralis";
function App() {
const { authenticate, isAuthenticated, user } = useMoralis();
const login = async () => {
if (!isAuthenticated) {
await authenticate({ provider: "walletconnect", chainId: 56 })
.then(function (user) {
console.log(user!.get("ethAddress"));
})
.catch(function (error) {
console.log(error);
});
}
}
}
要減少移動鏈接選項的數(shù)量或自定義其順序,請為 ?mobileLinks
?選項提供一組?wallet names
?,可以選擇使用?JS
?或者?React
?。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: