Mobile (WalletConnect)
Last updated
Was this helpful?
Was this helpful?
import { SignClient } from "@walletconnect/sign-client";
// Initialize Sign Client
const signClient = await SignClient.init({
projectId: "YOUR_PROJECT_ID", // Get from https://cloud.walletconnect.com
metadata: {
name: "Your dApp Name",
description: "Your dApp Description",
url: "https://yourdapp.com",
icons: ["https://yourdapp.com/icon.png"],
},
});
// Subscribe to session events
signClient.on("session_event", ({ event }) => {
// Handle session events
console.log("Session event:", event);
});
signClient.on("session_update", ({ topic, params }) => {
const { namespaces } = params;
const session = signClient.session.get(topic);
// Update session state
console.log("Session updated:", session);
});
signClient.on("session_delete", () => {
// Session was deleted, reset dApp state
console.log("Session disconnected");
});// Request session
try {
const { uri, approval } = await signClient.connect({
optionalNamespaces: {
eip155: {
methods: [
"eth_sendTransaction",
"personal_sign",
"eth_signTypedData",
],
chains: ["eip155:1"],
events: ["chainChanged", "accountsChanged"],
},
},
});
// ...
}function openMobileWallet(){
const deepLink = `https://link.trustwallet.com/wc?uri=${encodeURIComponent(uri)}`
window.open(deepLink, '_blank', 'noreferrer noopener')
}import { Cuer } from 'cuer'
export function QRCodeComponent() {
return uri && <Cuer arena={uri} />
}try {
// ...
// Await session approval from the wallet
const session = await approval();
console.log("Session established:", session);
} catch (error) {
console.error("Connection error:", error);
}