diff --git a/docs/docs/guides/web3_providers_guide/eip6963.md b/docs/docs/guides/web3_providers_guide/eip6963.md new file mode 100644 index 00000000000..c6d9b676804 --- /dev/null +++ b/docs/docs/guides/web3_providers_guide/eip6963.md @@ -0,0 +1,58 @@ +--- +sidebar_position: 2 +sidebar_label: 'EIP-6963: Multi Injected Provider Discovery' +--- + +# 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: + +```ts +export interface EIP6963ProviderDetail { + info: EIP6963ProviderInfo; + provider: EIP1193Provider; +} +``` + +where `info` has details of provider containing UUID, name, Icon and RDNS as defined in EIP-6963: + +```ts +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. + +```ts +//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')); + } +} + +``` \ No newline at end of file diff --git a/docs/docs/guides/web3_providers_guide/events_listening.md b/docs/docs/guides/web3_providers_guide/events_listening.md index 4208e4d2777..a8e36a3cd22 100644 --- a/docs/docs/guides/web3_providers_guide/events_listening.md +++ b/docs/docs/guides/web3_providers_guide/events_listening.md @@ -1,5 +1,5 @@ --- -sidebar_position: 2 +sidebar_position: 3 sidebar_label: 'Providers Events Listening' --- diff --git a/docs/docs/guides/web3_providers_guide/http.md b/docs/docs/guides/web3_providers_guide/http.md index c30db83873d..06dbc0d8125 100644 --- a/docs/docs/guides/web3_providers_guide/http.md +++ b/docs/docs/guides/web3_providers_guide/http.md @@ -1,5 +1,5 @@ --- -sidebar_position: 3 +sidebar_position: 4 sidebar_label: 'Tutorial: HTTP Provider' --- diff --git a/docs/docs/guides/web3_providers_guide/injected_provider.md b/docs/docs/guides/web3_providers_guide/injected_provider.md index 1088e576507..e6971629c58 100644 --- a/docs/docs/guides/web3_providers_guide/injected_provider.md +++ b/docs/docs/guides/web3_providers_guide/injected_provider.md @@ -1,5 +1,5 @@ --- -sidebar_position: 6 +sidebar_position: 7 sidebar_label: 'Tutorial: Injected provider' --- diff --git a/docs/docs/guides/web3_providers_guide/ipc.md b/docs/docs/guides/web3_providers_guide/ipc.md index fd7ad921cc1..1b31eb44f2b 100644 --- a/docs/docs/guides/web3_providers_guide/ipc.md +++ b/docs/docs/guides/web3_providers_guide/ipc.md @@ -1,5 +1,5 @@ --- -sidebar_position: 5 +sidebar_position: 6 sidebar_label: 'Tutorial: IPC Provider' --- diff --git a/docs/docs/guides/web3_providers_guide/truffle.md b/docs/docs/guides/web3_providers_guide/truffle.md index 0c52cb76902..ba98c3a3335 100644 --- a/docs/docs/guides/web3_providers_guide/truffle.md +++ b/docs/docs/guides/web3_providers_guide/truffle.md @@ -1,5 +1,5 @@ --- -sidebar_position: 7 +sidebar_position: 8 sidebar_label: 'Tutorial: Third Party Provider' --- diff --git a/docs/docs/guides/web3_providers_guide/websocket.md b/docs/docs/guides/web3_providers_guide/websocket.md index 5fd95c4e8cf..96288f4e031 100644 --- a/docs/docs/guides/web3_providers_guide/websocket.md +++ b/docs/docs/guides/web3_providers_guide/websocket.md @@ -1,5 +1,5 @@ --- -sidebar_position: 4 +sidebar_position: 5 sidebar_label: 'Tutorial: WebSocket Provider' ---