You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 2. Register a `display_uri` listener before connecting
49
+
50
+
The `display_uri` event fires on the EIP-1193 [provider](../reference/provider-api.md) during the connecting phase with a one-time-use pairing URI.
51
+
You **must** register the listener before calling `connect`, or you may miss the event:
52
+
53
+
```javascript
54
+
constprovider=evmClient.getProvider()
55
+
56
+
provider.on('display_uri', uri=> {
57
+
showCustomQrModal(uri)
58
+
})
59
+
```
60
+
61
+
As an alternative to `provider.on`, you can pass a `displayUri` callback when initializing the client via [`eventHandlers`](../reference/methods.md#createevmclient) (see the [migration guide](migrate-from-sdk.md#6-update-event-handling)).
62
+
63
+
### 3. Connect and handle the result
64
+
65
+
Call [`connect`](../reference/methods.md#connect) to connect to MetaMask, and handle the result:
66
+
67
+
```javascript
68
+
try {
69
+
awaitevmClient.connect({ chainIds: ['0x1'] })
70
+
hideCustomQrModal()
71
+
} catch (err) {
72
+
hideCustomQrModal()
73
+
if (err.code===4001) {
74
+
// User rejected — show retry UI
75
+
} else {
76
+
console.error('Connection failed:', err)
77
+
}
78
+
}
79
+
```
80
+
81
+
## Important considerations
82
+
83
+
### URI is one-time-use
84
+
85
+
The pairing URI delivered by `display_uri` is a one-time-use token.
86
+
Once used or expired, it cannot be reused.
87
+
If the connection fails, call `connect` again to generate a fresh URI.
88
+
89
+
### `display_uri` only fires during connecting
90
+
91
+
The event fires only while the client status is `'connecting'`.
92
+
After the connection resolves (success or error), `display_uri` stops firing.
93
+
94
+
### Extension connections skip QR
95
+
96
+
When the MetaMask browser extension is installed and `ui.preferExtension` is `true` (the default),
97
+
the SDK connects directly through the extension.
98
+
No `display_uri` event fires because no QR code is needed.
99
+
100
+
To display the QR connection option even when the extension is available, set `ui.preferExtension` to `false`:
Copy file name to clipboardExpand all lines: metamask-connect/evm/guides/interact-with-contracts.md
+23-13Lines changed: 23 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,25 +43,35 @@ With MetaMask Connect EVM:
43
43
44
44
The following examples demonstrate how to use MetaMask Connect EVM with viem, web3.js, ethers.js, Ethereum APIs, or Wagmi to interact with Solidity smart contracts.
45
45
46
-
This simple Hello World contract allows anyone to read and write a message to it.
46
+
## Prerequisites
47
47
48
-
```tsx
49
-
// SPDX-License-Identifier: GPL-3.0
50
-
pragmasolidity>=0.7.0<0.9.0;
48
+
- Follow the [JavaScript quickstart](../quickstart/javascript.md) or [Wagmi quickstart](../quickstart/wagmi.md) to install, initialize, and connect the EVM client.
49
+
- Create and deploy a simple smart contract. For example, the following contract allows anyone to read and write a message to it.
Copy file name to clipboardExpand all lines: metamask-connect/evm/guides/manage-networks.md
+24-53Lines changed: 24 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ import TabItem from '@theme/TabItem';
28
28
29
29
# Manage networks
30
30
31
-
Use MetaMask Connect EVM to detect, switch, and add EVM networks in your dapp. MetaMask Connect EVM supports `wallet_switchEthereumChain` for switching between networks, `wallet_addEthereumChain` for adding custom networks, and the `chainChanged` event for monitoring network changes in real time.
31
+
Use MetaMask Connect EVM to detect, switch, and add EVM networks in your dapp. MetaMask Connect EVM provides `getChainId` for detecting the current network, `switchChain` for switching between networks, and the `chainChanged` event for monitoring network changes in real time.
32
32
33
33
With MetaMask Connect EVM:
34
34
@@ -43,11 +43,15 @@ With MetaMask Connect EVM:
43
43
</a>
44
44
</p>
45
45
46
+
## Prerequisites
47
+
48
+
Follow the [JavaScript quickstart](../quickstart/javascript.md) or [Wagmi quickstart](../quickstart/wagmi.md) to install, initialize, and connect the EVM client.
49
+
46
50
## Detect and switch networks
47
51
48
-
With Vanilla JavaScript, implement network management directly using the
49
-
[`eth_chainId`](../reference/json-rpc-api/eth_chainId.mdx) RPC method and
0 commit comments