Connecting
Establish a WalletConnect session with the Varial mobile app, handle session lifecycle events, and disconnect.
Assumes provider and modal are initialized as shown in Installation.
Creating a Session
Call modal.open() to show the wallet selection modal, then provider.connect() to start the pairing. The modal displays a QR code and a list of wallets — when the user selects Varial or scans the QR code, the connection is established automatically. connect() resolves once the wallet approves.
// Open the modal (shows a spinner, then the QR code and wallet list)
modal.open();
// Connect — resolves when the wallet approves
const session = await provider.connect({
namespaces: {
stellar: {
methods: [
"stellar_signXDR",
"stellar_signAndSubmitXDR",
"stellar_signMessage",
"stellar_signAuthEntry",
],
chains: ["stellar:pubnet"],
events: ["accountsChanged"],
},
},
});
if (!session) {
throw new Error("Connection failed");
}
modal.close();
console.log("Connected! Session topic:", session.topic);The connected session is also accessible at any time via provider.session.
Accounts are stored in session.namespaces.stellar.accounts as "stellar:pubnet:G..." strings — split on : to extract the public key:
Handling Events
Listen for session lifecycle events to keep your UI in sync:
Disconnecting
When the user wants to disconnect:
Next steps
Once connected, you can sign transactions, messages, and auth entries.
Last updated
Was this helpful?