Skip to Content
dApps

Detecting the Provider

To detect if a user has already installed OneKey, a web application should check for the existence of a window.$onekey.solana object.

OneKey Browser Extension, OneKey Mobile APP and OneKey Desktop in-app browser can inject a $onekey.solana object into supported browsing contexts.

If a window.$onekey.solana object exists, Solana apps can interact with OneKey via the API found at window.$onekey.solana. This solana object is also available at window.solana to support legacy integrations.

To detect if OneKey is installed, an application should check for an additional isOneKey flag.

const isOneKeyInstalled = window.$onekey?.solana?.isOneKey;

If OneKey is not installed, we recommend you redirect your users to https://onekey.so/download/?client=browserExtension . Altogether, this may look like the following.

const getProvider = () => { if ('$onekey' in window) { const provider = window.$onekey?.solana; if (provider?.isOneKey) { return provider; } } return undefined; // Show an installation link in the application UI. };

If getProvider() returns undefined, show an installation or enable-wallet action and stop the connection flow. Open external links only in response to a user action.

Last updated on