The purpose of this guide is to show the best practices in regards of the WalletKit client usage. The goal is to provide the best user experience that just works in every circumstances.
In order to ensure the best user experience and flawless connection flow, please make sure that WalletKit is initialized immediately after your app launch, especially if launched via a WalletConnect Deep Link. It guarantees that websocket connection is opened immediately and all requests are received by your wallet
A pairing is a connection between a wallet and a dapp that has fixed permissions to only allow a dapp to propose a session through it. Dapp can propose infinite number of sessions on one pairing. Wallet must use a pair method from the WalletKit client to pair with dapp.
Copy
const uri = 'xxx'; // pairing uritry { await walletKit.pair({ uri });} catch (error) { // some error happens while pairing - check Expected errors section}
A pairing expiry event is triggered whenever a pairing is expired. The expiry for inactive pairing is 5 mins, whereas for active pairing is 30 days. A pairing becomes active when a session proposal is received and user successfully approves it. This event helps to know when given pairing expires and update UI accordingly.
Copy
core.pairing.events.on("pairing_expire", (event) => { // pairing expired before user approved/rejected a session proposal const { topic } = topic;});
A session proposal is a handshake sent by a dapp and it’s purpose is to define a session rules. Whenever a user wants to establish a connection between a wallet and a dapp, one should approve a session proposal.
Whenever user approves or rejects a session proposal, wallet should show loading indicators in a moment of the button press until Relay acknowledgement is received for any of this actions.Approving session
Copy
try { await walletKit.approveSession(params); // update UI -> remove the loader } catch (error) { // present error to the user }
Rejecting session
Copy
try { await walletKit.rejectSession(params); // update UI -> remove the loader } catch (error) { // present error to the user }
A session proposal expiry is 5 mins. It means a given proposal is stored for 5 mins in the SDK storage and user has 5 mins for approval or rejection decision. After that time the below event is emitted and proposal modal should be removed from the app’s UI.
Copy
walletKit.on("proposal_expire", (event) => { // proposal expired and any modal displaying it should be removed const { id } = event;});
Whenever user approves or rejects a session request, wallet should show loading indicators in a moment of the button press until Relay acknowledgement is received for any of this actions.
Copy
try { await walletKit.respondSessionRequest(params); // update UI -> remove the loader } catch (error) { // present error to the user }
A session request expiry is defined by a dapp. It’s value must be between now() + 5mins and now() + 7 days. After the session request expires the below event is emitted and session request modal should be removed from the app’s UI.
Copy
walletKit.on("session_request_expire", (event) => { // request expired and any modal displaying it should be removed const { id } = event;});
The Web Socket connection state tracks the connection with the relay server, event is emitted whenever a connection state changes.
Copy
core.relayer.on("relayer_connect", () => { // connection to the relay server is established})core.relayer.on("relayer_disconnect", () => {// connection to the relay server is lost})