Skip to main content

Wallet Guide Section Topics

  • WalletConnect Code/Component Setup
  • Approving a Session Proposal
  • Rejecting a Session Proposal
  • Handling Session Request Events
  • Session Persistence/Management

  1. Getting Started: Generate a unique projectId by visiting and creating your project’s profile on WalletConnect’s project dashboard at:
    • https://dashboard.reown.com/

WalletConnect Code/Component Setup

  1. Import Core and WalletKit from WalletConnect.
  1. Instantiate and add Core and WalletKit to the state of the wallet.
  1. Create a function to accept a session uri which will be passed from a dapp when a user either scans the dapp’s WalletConnect qrcode modal or manually copies and pastes the uri from the modal into the wallet’s UI.
  1. Handle the session_proposal event on the walletKit. This event is triggered when the pair method is called on walletKit.core.pairing to create a pairing session.

Approving a Session Proposal (Example)

When approving a session proposal, the wallet can perform any necessary checks such as ensuring that the proposal includes all required namespaces and any optional namespaces. The approval response also contains the approved accounts as part of the namespace. Below is an example showing the format for wallet accounts and how to include them in a session proposal approval.

Rejecting a Session Proposal (Example)

If the user does not approve the requested chains, methods, or accounts, or if the wallet does not support the requested chains or methods, the response should not be considered a success. Below is an example of rejecting a session proposal.

Handling Session Request Event

A dapp triggers an event when it requires the wallet to carry out a specific action, such as signing a transaction. The event includes a topic and a request object, which will differ based on the requested action. As seen in the WalletConnect Web Examples, two common use cases in polkadot are signing messages and signing transactions. These methods are represented here as polkadot_signMessage and polkadot_signTransaction respectively and each simply signs the respective payload and returns the signature to the dapp. An example of a session_request event handler containing both can be found below.

Sessions Persistence/Management

  • sessions can be saved/stored so users don’t have to pair repeatedly
  • sessions can be disconnected from using await walletKit.disconnectSession({ topic: topic }); passing the session topic.
  • sessions can be extended using await walletKit.extendSession({ topic: topic }); passing the session topic.
  • Default session lifetime is 7 days for WalletConnect v2.0.

Further Documentation for WalletConnect 2.0