Dapp Integration Guide
Dapp Guide Section Topics
- WalletConnect Code/Component Setup
- Constructing unsigned transactions
- Sending unsigned transactions for signing using WalletConnect
- Adding the signature to the ExtrinsicPayload
- Signing and sending the transaction to the node
WalletConnect Code/Component Setup
-
One time step: Generate a unique
projectId
by visiting and creating your project’s profile on WalletConnect’s project dashboard at: https://cloud.reown.com/. -
Import
UniversalProvider
and{ WalletConnectModal }
from@walletconnect/universal-provider
and@walletconnect/modal
respectively.
- Instantiate a universal provider using the
projectId
created for your app.
- On user action (e.g. user clicks connect for WalletConnect), call the connect method on the providers sign client passing in preferred params.
WalletConnect uses chain ids based on the CAIP standard (CAIP-13 for Polkadot Namespace): Polkadot WalletConnect CAIP-13
-
polkadot CAIP id =
91b171bb158e2d3848fa23a9f1c25182
-
kusama CAIP id =
b0a8d493285c2df73290dfb7e61f870f
-
westend CAIP id =
e143f23803ac50e8f6f8e62695d1ce9e
-
statemint CAIP id =
68d56f15f85d3136970ec16946040bc1
-
hydradx CAIP id =
afdc188f45c71dacbaa0b62e16a91f72
-
phala network CAIP id =
1bb969d85965e4bb5a651abbedf21a54
-
astar network CAIP id =
9eb76c5184c4ab8679d2d5d819fdf90b
-
crust shadow CAIP id =
d4c0c08ca49dc7c680c3dac71a7c0703
-
mangata kusama mainnet CAIP id =
d611f22d291c5b7b69f1e105cca03352
-
turing network CAIP id =
0f62b701fb12d02237a33b84818c11f6
-
Chain ids correspond to the genesis hash for each respective chain
Example Namespace and Sign Client connect call:
Note: this serves as an example where a dapp requires 3 different chain namespaces (polkadot, hydradx and turing network). The supported methods, chains, and events can all be defined by the dapp team based on the requirements of the dapp.
- Create a standalone modal using your dapps WalletConnect projectId.
- Open the modal prompting the user to scan the QR code with their wallet app or copy the URI from the modal and paste into their wallet app to begin the session creation process.
- Get the accounts from the session for use in constructing transactions.
Constructing Unsigned Transactions
One thing the dapp must do is properly construct the unsigned transaction. This consists of constructing an object with the intended chain’s metadata including the specVersion
, transactionVersion
, etc. In addition to these, you must provide the transaction data (method
, address
etc). Below is an example of what this general structure looks like using polkadotjs but this can be done in any valid way:
- A specific example of constructing an unsigned transaction using polkadotjs api to retrieve the chains metadata.
Sending unsigned transactions to the wallet for signing using WalletConnect
- Send the unsigned transaction to the paired wallet for signing using the providers sign client. This triggers a
session_request
event which must be handled by the paired wallet.
Polkadot Example
Parachain Example (HydraDX)
Once the request is resolved, the expected response should be a result object which contains a signature
Adding the signature to the ExtrinsicPayload
Using this signature, we can now create an ExtrinsicPayload
and add the signature. Below is an example of this general step:
Signing and sending the transaction to the node
Now, it is just about attaching the returned signature to the transaction and submitting it as specified by the dApp. Below is a specific example showing this process:
Was this page helpful?