Connect from Android
Connect your dApp to the Keon Android app with deep links, then send transactions and sign messages
When someone opens your dApp in Chrome (or any other browser) on an Android phone, there is no extension to talk to. Instead, your dApp talks to the Keon app over WalletConnect, and a tap on a link opens Keon so the user can approve.
It works in four steps:
- Your dApp creates a pairing and shows an Open in Keon button.
- The user taps it. Keon opens and asks them to connect.
- They approve, and your dApp gets their address.
- Your dApp sends transactions or messages to sign. Keon opens for each one and returns to the browser when the user answers.
Everything here comes from starknet-tokenkit/keon-wallet/mobile. The Keon test dApp uses exactly this code; open it on your phone to try the flow.
If your dApp is opened inside Keon's own in-app browser, you don't need any of this: Keon injects the wallet there, just like the extension. Use StarknetKit or starknet-react, or KeonMobileConnector, which picks the right path for you.
1. Install
1npm install starknet-tokenkit starknet starknetkit @walletconnect/sign-client2. Create the connector
1import { KeonMobileBaseConnector } from 'starknet-tokenkit/keon-wallet/mobile'2 3const connector = new KeonMobileBaseConnector({4 dappName: 'My dApp',5 url: window.location.origin,6 icons: ['https://my-dapp.xyz/icon.png'],7 chainId: 'SN_MAIN', // or 'SN_SEPOLIA'8 projectId: 'your-walletconnect-project-id', // from cloud.reown.com9 10 // Called with the pairing link once it's ready: show the button.11 onDisplayUri: (uri) => showConnectButton(uri),12 13 // Called for every request while Keon has not answered yet (see step 5).14 onWakeWallet: (href, settled) => {15 showOpenKeonButton(href)16 settled.finally(hideOpenKeonButton)17 },18})chainId must match the network the user has selected in Keon. Keon refuses requests for a network it is not on.
3. Show the Open in Keon button
getDeepLink(uri) returns the right link for the browser your dApp is running in:
link.kind | Where | What to show |
|---|---|---|
intent | Chrome on Android | A button with href={link.href}. It opens Keon directly, or the Keon website if the app isn't installed. |
app_link | Other phone browsers | A button with href={link.href}. It opens Keon through its verified link. |
qr | Desktop | A QR code of the pairing uri itself, for the user to scan with Keon's scanner on their phone. |
1import { getDeepLink } from 'starknet-tokenkit/keon-wallet/mobile'2 3function ConnectButton({ uri }: { uri: string }) {4 const link = getDeepLink(uri)5 if (link.kind === 'qr') return <QRCode value={uri} />6 return <a href={link.href}>Open in Keon</a>7}4. Connect
Call connect() when the user taps your Connect button. It creates the pairing (which calls onDisplayUri), then waits until the user approves in Keon:
1const { account: address, chainId } = await connector.connect()2console.log('Connected:', address)If the user rejects in Keon, connect() throws.
5. Send a transaction
Get a starknet.js account from the connector. Pass a provider for your own reads (balances, nonces, fee estimates); writes go to Keon:
1import { RpcProvider } from 'starknet'2 3const provider = new RpcProvider({ nodeUrl: 'https://your-starknet-rpc' })4const account = await connector.account(provider)5 6const { transaction_hash } = await account.execute([7 {8 contractAddress: '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d', // STRK9 entrypoint: 'transfer',10 calldata: [recipient, amountLow, amountHigh],11 },12])What the user sees:
- On Chrome for Android, Keon opens by itself as soon as the transaction is sent, straight on that request. After they approve or reject, Keon takes them back to Chrome.
- In other browsers,
onWakeWalletgives you a link. Show it as an Open Keon button until the request settles. The user taps it, answers in Keon, and switches back.
Keep the Open Keon button even on Chrome. It covers the rare case where the browser blocks the jump, and reads that go through the wallet.
To turn off the automatic opening, pass autoOpenWallet: false to the connector.
6. Sign a message
1const typedData = {2 types: {3 StarknetDomain: [4 { name: 'name', type: 'shortstring' },5 { name: 'version', type: 'shortstring' },6 { name: 'chainId', type: 'shortstring' },7 { name: 'revision', type: 'shortstring' },8 ],9 Message: [{ name: 'content', type: 'shortstring' }],10 },11 primaryType: 'Message',12 domain: { name: 'My dApp', version: '1', chainId: 'SN_MAIN', revision: '1' },13 message: { content: 'Sign in to My dApp' },14}15 16const signature = await account.signMessage(typedData)Keon shows the message before signing. Set domain.chainId to the network you are on: Keon warns the user when it doesn't match. If your message lets someone else send transactions (an outside execution) or move tokens, Keon shows a red warning, so keep sign-in messages plain.
7. Other requests
For anything without a helper, send a wallet request directly:
1const wallet = connector.wallet2 3await wallet.request({ type: 'wallet_addInvokeTransaction', params: { calls } })4await wallet.request({ type: 'wallet_signTypedData', params: typedData })5await wallet.request({ type: 'wallet_addDeclareTransaction', params: declarePayload })Over WalletConnect, the user switches networks inside Keon; your dApp hears about it through the connector's change event.
8. Disconnect
1await connector.disconnect()The user can also disconnect from Keon (Apps, Connected apps). Listen for it:
1connector.on('disconnect', () => {2 // Show your Connect button again3})Already using your own WalletConnect client?
If your dApp creates its own SignClient instead of using the connector, add Keon's links yourself:
1import { getDeepLink, getWakeLink, openKeonOnRequest } from 'starknet-tokenkit/keon-wallet/mobile'2 3// Connect: show getDeepLink(uri) as the button4const { uri, approval } = await client.connect({ optionalNamespaces: { starknet: { chains, methods, events } } })5showConnectButton(uri!) // renders getDeepLink(uri), as in step 36const session = await approval()7 8// Requests: open Keon by itself on Chrome for Android (once per session)9openKeonOnRequest(client, session.topic)10 11// Elsewhere: an Open Keon button for a waiting request12showOpenKeonButton(getWakeLink(session.topic))Good to know
- Keon has to be open to answer. Android pauses apps in the background, so a request waits until Keon is on screen. That's what the automatic opening and the Open Keon button are for.
- A link never approves anything. Keon always shows its full approval screen.
- Pairing links are safe to show. They only go to Keon's verified link (
https://keon.tokenkithq.io/wc) or, on Chrome, to an intent addressed to the Keon app, never to a barekeonwallet://link another app could claim. - Same network on both sides. If the user switches networks in Keon, your dApp gets a
changeevent from the connector; requests for the old network are refused.