A JavaScript Ethereum Provider API for consistency across clients and applications.
Why It Matters
EIP-1193 defines a consistent standard for browser-extension-based
Ethereum wallets to integrate with web applications. This allows
web applications to interact with the wallet and the Ethereum blockchain
without needing to implement wallet-specific code.
The injected provider script of the Chrome Web Store package (requestProvider.js, version 3.149.0, .crx file SHA-256 40e8e5ce04bc3266c7a7bda57a80213b441a8af8afabcd0232cf81036ddd0ce6) exposes an EIP-1193 request method and on/removeListener event subscriptions (EIP-2700). It dispatches eip6963:announceProvider with the name "Coinbase Wallet" and the rdns com.coinbase.wallet, and announces again on each eip6963:requestProvider event (EIP-6963).
3637constrainbowProvider=newRainbowProvider({38 backgroundMessenger,39 providerRequestTransport: providerRequestTransport,40onConstruct({ emit }) {41// RainbowInjectedProvider is also used in popup via RainbowConnector42// here we don't need to listen to anything so we don't need these listeners43if (isValidUrl(window.location.href)) {44consthost=getDappHost(window.location.href);45 backgroundMessenger?.reply(`accountsChanged:${host}`, async (address) => {46emit('accountsChanged', [address]);47 });48 backgroundMessenger?.reply(49`chainChanged:${host}`,50async (chainId:number) => {51emit('chainChanged', toHex(String(chainId)));52 },53 );54 backgroundMessenger?.reply(`disconnect:${host}`, async () => {55emit('accountsChanged', []);56emit('disconnect', []);57 });58 backgroundMessenger?.reply(`connect:${host}`, async (connectionInfo) => {59emit('connect', connectionInfo);60 });61 }62 },63});6465if (shouldInjectProvider()) {
93constproxiedProvider=newProxy(patchedProvider, {...103set(target, prop, value, receiver) {...111 }112 },113});114115window.ethereum = proxiedProvider;116117dappDetection.onChange(({ dappIsZerionAware }) => {118if (dappIsZerionAware) {119// Some libs (such as rainbow) access "isZerion" flag120// to filter out wallets, and it doesn't mean the dapp is showing121// the connect button for Zerion specifically. This is why we122// do not turn off the page observer. But we might change this later.123// pageObserver.stop();124 }125});126127try {128 Object.defineProperty(window, 'ethereum', {129 configurable: false, // explicitly set to false to disallow redefining the property by other wallets130get() {131if (isPaused && competingProviders.hasOtherProviders()) {132return competingProviders.getFirstOtherProvider();133 }134 dappDetection.onAccessThroughWindow();135return proxiedProvider;136 },137set(value:EthereumProvider) {138 dappDetection.handleForeignProvider(value);139 competingProviders.handleForeignProvider({140 foreignProvider: value,141 ourProvider: provider,142 });143 },144 });145} catch {146// eslint-disable-next-line no-console147 console.warn('Failed to set window.ethereum');148}149
18typeOptions= {19onRequestProvider?: () =>void;20onAccessProvider?: () =>void;21};2223exportfunctioninitializeEIP6963(24provider:EthereumProvider,25options?:Options26) {27constproviderDetail= { info, provider };28 Object.defineProperty(providerDetail, 'provider', {29get() {30// We add this getter to be able to detect that a dapp supports EIP-696331// We can't rely solely on 'eip6963:requestProvider', because technically dapp32// can listen to our initial 'eip6963:announceProvider' event33// and never dispatch the request event.34 options?.onAccessProvider?.();35return provider;36 },37 });38constannounceEvent=newCustomEvent('eip6963:announceProvider', {39 detail: Object.freeze(providerDetail),40 });41 window.dispatchEvent(announceEvent);4243 window.addEventListener('eip6963:requestProvider', () => {44 window.dispatchEvent(announceEvent);45 options?.onRequestProvider?.();46 });47}