OneKey Docs
  • 👋GUIDE
    • Introduction
    • Web App Integration Developer
    • Hardware Integration Developer
    • External Contribution Guide
    • Common Terms
  • 🔮Connect To Software
    • Compatible with Metamask
      • detectEthereumProvider
    • Support Wallet Kit
      • Web3 Onboard
      • Rainbowkit
      • Aptos Wallet Adapter
      • Web3Modal
    • WebApp Connect OneKey
      • ETH
        • Provider API
        • RPC API
        • Accessing Accounts
        • Sending Transactions
        • Signing Data
      • BTC
        • Guide
        • API Reference
          • requestAccounts
          • getAccounts
          • getNetwork
          • switchNetwork
          • getPublicKey
          • getBalance
          • getInscriptions
          • sendBitcoin
          • sendInscription
          • signMessage
          • pushTx
          • signPsbt
          • signPsbts
          • pushPsbt
          • inscribeTransfer (Deprecated)
        • Event
      • Nostr
        • Guide
        • API Reference
          • getPublicKey
          • signEvent
          • signSchnorr
          • getRelays
          • nip04.encrypt
          • nip04.decrypt
        • Event
      • WebLN
        • Guide
        • API Reference
          • enable
          • getInfo
          • makeInvoice
          • sendPayment
          • signMessage
          • verifyMessage
          • lnurl
          • getBalance
        • Event
      • NEAR
        • Introduction
        • Integrating
          • Install the Provider SDK
          • Detecting the Provider
          • Establishing a Connection
          • Accessing Accounts
          • Detecting Provider Network
          • Watch Accounts & Network Status
          • Sending Transactions
            • Create Transaction
            • Sign and Send Transaction
            • Signing Transaction
          • Signing Messages
          • RPC API Calling
          • Debug Logging
          • Migrate from Near Web Wallet
        • Reference
          • API Reference
          • Trouble Shooting
        • Resources
          • Example & Demo
          • FAQ
      • SOLANA
        • Detecting the Provider
        • Establishing a Connection
        • Sending a Transaction
        • Signing a Message
    • Using WalletConnect
      • ETH
      • APTOS
        • Wallet Connect API
  • 📟Connect to Hardware
    • Hardware SDK
      • Started
      • Install SDK
      • Config Event
      • Common Params
      • Path Params
      • Error Code
      • API Reference
        • Basic API
          • Init SDK
          • Search Devices
          • Get Features
          • Get Passphrase State
          • Cancel Request
          • Response UI Event
        • Device API
          • deviceSupportFeatures
          • checkBridgeStatus
          • checkTransportRelease
          • checkFirmwareRelease
          • checkBLEFirmwareRelease
          • deviceChangePin
          • deviceReset
          • deviceSettings
          • deviceUpdateReboot
          • deviceVerify
          • deviceWipe
          • firmwareUpdate
        • Bitcoin & Bitcoin forks
          • btcGetAddress
          • btcGetPublicKey
          • btcSignMessage
          • btcSignTransaction
          • btcVerifyMessage
        • Ethereum & EVM
          • evmGetPublicKey
          • evmGetAddress
          • evmSignTransaction
          • evmSignTypedData
          • evmSignMessage
          • evmVerifyMessage
        • Algorand
          • algoGetAddress
          • algoSignTransaction
        • Aptos
          • aptosGetAddress
          • aptosGetPublicKey
          • aptosSignMessage
          • aptosSignTransaction
        • Alephium
          • alephiumGetAddress
          • alephiumSignMessage
          • alephiumSignTransaction
        • Cardano
          • cardanoGetAddress
          • cardanoGetPublicKey
          • cardanoSignMessage
          • cardanoSignTransaction
        • Conflux
          • confluxGetAddress
          • confluxSignMessage
          • confluxSignMessageCIP23
          • confluxSignTransaction
        • Cosmos
          • cosmosGetAddress
          • cosmosGetPublicKey
          • cosmosSignTransaction
        • Dynex
          • dnxGetAddress
          • dnxSignTransaction
        • FileCoin
          • filecoinGetAddress
          • filecoinSignTransaction
        • Kaspa
          • kaspaGetAddress
          • kaspaSignTransaction
        • Near
          • nearGetAddress
          • nearSignTransaction
        • Nervos
          • nervosGetAddress
          • nervosSignTransaction
        • Nostr
          • nostrGetPublicKey
          • nostrSignEvent
          • nostrSignSchnorr
          • nostrEncryptMessage
          • nostrDecryptMessage
        • NEM
          • nemGetAddress
          • nemSignTransaction
        • Nexa
          • nexaGetAddress
          • nexaSignTransaction
        • Polkadot
          • polkadotGetAddress
          • polkadotSignTransaction
        • Ripple
          • xrpGetAddress
          • xrpSignTransaction
        • Scdo
          • scdoGetAddress
          • scdoSignMessage
          • scdoSignTransaction
        • Solana
          • solGetAddress
          • solSignTransaction
        • Starcoin
          • startcoinGetAddress
          • starcoinGetPublicKey
          • starcoinSignMessage
          • starcoinSignTransaction
          • starcoinVerifyMessage
        • Stellar
          • stellarGetAddress
          • stellarSignTransaction
        • Sui
          • suiGetAddress
          • suiGetPublicKey
          • suiSignMessage
          • suiSignTransaction
        • Tron
          • tronGetAddress
          • tronSignMessage
          • tronSignTransaction
        • Ton
          • tonGetAddress
          • tonSignMessage
          • tonSignProof
      • Advanced
        • Passphrase
        • Common SDK Guide
        • Low-level transport plugin
        • OneKey Message Protocol
      • Tutorial: Get started with OneKey
    • Air Gap SDK
      • Started
      • Tutorial: Wallet Integration
      • API Reference
        • Basic API
          • CryptoHDkey
          • CryptoCoinInfo
          • CryptoKeypath
        • Ethereum & EVM
          • EthSignRequest
          • EthSignature
  • ⛳Best Practice
    • Registering Your Contract's Method Names
    • Registering Tokens with Users
    • Defining Your App's Icon
    • Migration from MetaMask
  • 🎨Logo Assets
  • 🧙Support
  • 🕹️Trouble Shooting
  • ❤️Contribute
Powered by GitBook
On this page
  • Introduction
  • Compatible with MetaMask
  • Using Wallet Kit
  • How to Determine if it is OneKey Provider

Was this helpful?

Edit on GitHub
  1. Connect To Software

Compatible with Metamask

PreviousCommon TermsNextdetectEthereumProvider

Last updated 1 month ago

Was this helpful?

Introduction

In the development of blockchain applications, Ethereum and its compatible EVM chains are the first choice for developers. MetaMask wallet, as a key component for EVM-based DApp development, is often the primary object for compatibility testing.

Wallets developed for EVM chains, such as OneKey and MetaMask, both follow the standard to implement the Provider API. In most cases, a DApp that is compatible with MetaMask can be used directly with OneKey without any modification.

In special cases, when both OneKey and MetaMask extensions are present, a conflict may occur during the DApp connection process. This conflict results in an inability to select which extension should respond to the connection request, and users might need to disable one extension to continue.

To address this issue, we provide the following solutions: Users can manually disable an extension to prevent conflicts. Developers can specify in the code which Provider API to use preferentially, reducing the steps users need to take. With these solutions, both users and developers can enjoy a smoother experience, whether they are using OneKey or MetaMask wallets.

Compatible with MetaMask

OneKey provides the Provider API through window.ethereum and window.$onekey.ethereum. Developers should call window.$onekey.ethereum preferentially, and if OneKey is not installed, then use other wallets' API.

const provider = (window.$onekey && window.$onekey.ethereum) || window.ethereum;
// Connect to Wallet
await provider.enable()

If OneKey is installed, window.ethereum may point to OneKey API, which could lead to a plugin conflict. To address this, OneKey has introduced the Wallet Switch feature, which turns off MetaMask compatibility mode to avoid conflicts and enhance the experience.

To resolve this issue, OneKey has launched the Wallet Switch feature. This feature, by turning off MetaMask's compatibility mode, ensures that OneKey only injects its exclusive window.$onekey.ethereum Provider API, avoiding potential conflicts and thus optimizing the user experience. If users prefer OneKey and want to avoid frequent wallet switching, it is recommended to enable the Wallet Switch feature.

Using Wallet Kit

There are also some wallet Kits that support the OneKey API that can be used directly.

With wallet kit, you don't have to worry about and consider the above adaptation problems with Metamask, which is handled in the kits.

How to Determine if it is OneKey Provider

OneKey's Provider API offers a unique method, isOneKey. Developers can call this method, and if the return value is true, then it is confirmed that the current Provider API is injected by OneKey. This helps to accurately identify and select the correct Provider in a multi-wallet scenario, ensuring the DApp operates normally.

An example of use is as follows:

if (provider.isOneKey && provider.isOneKey()) {
  console.log('The current provider comes from OneKey');
}

This method helps to avoid conflicts in environments where both OneKey and other wallets that follow the EIP-1193 standard (like MetaMask) are installed.

🔮
EIP-1193
Full Demo >>>
Web3 Onboard >>>
Rainbow Kit >>>