Skip to main content

Wallet Usage

caution

Auth API is in the process of being greatly simplified, and will involve breaking changes. Please stand by.

info

For an example implementation, please refer to our react-wallet-auth example.

1. Initialize your WalletConnect AuthClient, using your Project ID.

import AuthClient from '@walletconnect/auth-client'

const authClient = await AuthClient.init({
projectId: '<YOUR_PROJECT_ID>',
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. Listen to authentication requests

info

To listen to pairing-related events, please follow the guidance for Pairing API event listeners

authClient.on('auth_request', async ({ id, params }) => {
// the user’s address
const iss = `did:pkh:eip155:1:${WALLET_ADDRESS}`

// format the cacao payload with the user’s address
const message = authClient.formatMessage(params.cacaoPayload, iss)

// 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'
}
},
iss
)
})

3. Scan QR Code (or paste URI directly)

Once a QR code is scanned, a pairing must be established using the embedded URI. This is what allows the auth_request events to be received.

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