Skip to main content

EIP-6963: Multi Injected Provider Discovery

Introduction

EIP-6963 proposes the "Multi Injected Provider Discovery" standard, which aims to enhance the discoverability and interaction with multiple injected Ethereum providers in a browser environment. Injected providers refer to browser extensions or other injected scripts that provide access to an Ethereum provider within the context of a web application.

Web3.js library has utility function for discovery of injected providers using requestEIP6963Providers() function. When requestEIP6963Providers() is used it returns eip6963Providers Map object. This Map object is in global scope so every time requestEIP6963Providers() function is called it will update Map object and return it.

eip6963Providers Map object has provider's UUID as keys and EIP6963ProviderDetail as values. EIP6963ProviderDetail is:

export interface EIP6963ProviderDetail {
info: EIP6963ProviderInfo;
provider: EIP1193Provider;
}

where info has details of provider containing UUID, name, Icon and RDNS as defined in EIP-6963:

export interface EIP6963ProviderInfo {
uuid: string;
name: string;
icon: string;
rdns: string;
}

provider in EIP6963ProviderDetail is EIP1193Provider and it contains actual provider that can be injected in web3 instance.

Following code snippet demonstrates usage of requestEIP6963Providers() function for providers discovery.

//Assuming multiple providers are installed in browser. 

import { Web3 } from 'web3';

const providers = Web3.requestEIP6963Providers();

for (const [key, value] of providers) {
console.log(value);

/* Based on your DApp's logic show use list of providers and get selected provider's UUID from user for injecting its EIP6963ProviderDetail.provider EIP1193 object into web3 object */

if (value.info.name === 'MetaMask') {
const web3 = new Web3(value.provider);

// now you can use web3 object with injected provider
console.log(await web3.eth.getTransaction('0x82512812c11f56aa2474a16d5cc8916b73cd6ed96bf9b8defb3499ec2d9070cb'));
}
}