跳到主要内容

Wallet 用法

信息

关于示例实现,请参考我们的react-wallet-auth example

1. 初始化WalletConnect AuthClient,使用您的项目ID

import AuthClient from "@walletconnect/auth-client";

const authClient = await AuthClient.init({
projectId: "<YOUR_PROJECT_ID>",
iss: `did:pkh:eip155:1:<WALLET_ADDRESS>`,
metadata: {
name: "my-auth-wallet",
description: "A wallet using WalletConnect AuthClient",
url: "my-auth-wallet.com",
icons: ["https://my-auth-wallet.com/icons/logo.png"],
},
});

2. 监听身份验证请求

信息

要收听与配对相关的事件,请遵循配对API事件监听器的指导。

authClient.on("auth_request", async ({ id, params }) => {
// This is a good point to trigger a UI event to provide the user
// with a button to accept or reject the authentication request,
// instead of automatically responding.
const signature = await wallet.signMessage(params.message);
await authClient.respond({
id: id,
signature: {
s: signature,
t: "eip191",
},
});
});

3. 扫描二维码(或直接粘贴URI)

扫描二维码后,必须使用嵌入的URI建立配对。 这就是允许auth_request事件被接收的原因。

await authClient.core.pairing.pair({ uri });