Provider Injection

The Provider Injection Pattern

The provider injection pattern enables wallet extensions to expose blockchain functionality to web applications. The wallet injects a provider property into the browser's window object, allowing applications to detect the wallet and interact with the blockchain through the exposed interface.

Known Examples:

  • OP_WALLET: window.opnet
  • Unisat Wallet: window.unisat
  • Xverse Wallet: window.XverseProviders

Multiple Wallet War

Multiple wallets may attempt to inject the same property name. When this occurs, the last wallet to initialize will overwrite previous injections, making only that wallet accessible to the user.

This behavior is unpredictable (initialization order varies) and creates a poor user experience. Always use a unique property name for your wallet to avoid conflicts.

Identifying the Injected Property

To identify the injected property for a specific wallet, use one of these methods:

  • Check the wallet extension's documentation.
  • Review the wallet extension's source code (if available).
  • Inspect the window object directly in the browser console by typing window and pressing Enter.
Window object samplejavascript

13:33:12.699 window <ENTER>
13:33:12.704 Window {
0: Window,
1: global,
window: Window,
...
self: Window, document: document, name: '', location: Location, …},
XverseProviders: {StacksProvider: {…}, BitcoinProvider:},
cancelAnimationFrame: ƒ cancelAnimationFrame()cancelIdleCallback: …
...