Skip to content

Commit bd17d74

Browse files
Various SDK doc fixes (#2195)
* Various SDK doc fixes * add SDK methods reference * add isInitialized() * minor fix
1 parent 37056bc commit bd17d74

16 files changed

+200
-112
lines changed

sdk-sidebar.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,8 @@ const sidebar = {
3232
'guides/handle-transactions',
3333
'guides/interact-with-contracts',
3434
'guides/use-deeplinks',
35-
{
36-
type: 'category',
37-
label: 'Advanced',
38-
collapsible: true,
39-
collapsed: true,
40-
items: [
41-
'guides/advanced/connect-and-sign',
42-
'guides/advanced/batch-requests',
43-
'guides/advanced/production-readiness',
44-
],
45-
},
35+
'guides/batch-requests',
36+
'guides/production-readiness',
4637
],
4738
},
4839
{
@@ -61,6 +52,7 @@ const sidebar = {
6152
'reference/llm-prompt',
6253
'reference/supported-platforms',
6354
'reference/sdk-options',
55+
'reference/sdk-methods',
6456
],
6557
},
6658
],

sdk/connect/react-native.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ For example:
176176
import { useSDK } from "@metamask/sdk-react"
177177

178178
function App() {
179-
const { connect, disconnect, account, chainId, ethereum } = useSDK()
179+
const { connect, terminate, account, chainId, ethereum } = useSDK()
180180

181181
// Connect to MetaMask
182182
const connectWallet = async () => {
@@ -196,7 +196,7 @@ function App() {
196196

197197
// Disconnect wallet
198198
const disconnectWallet = async () => {
199-
await disconnect()
199+
await terminate()
200200
}
201201

202202
return (

sdk/guides/advanced/connect-and-sign.md

Lines changed: 0 additions & 97 deletions
This file was deleted.

sdk/guides/authenticate-users.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
description: Authenticate users with the SDK in your Wagmi or Vanilla JavaScript dapp.
3-
toc_max_heading_level: 2
3+
keywords: [SDK, Wagmi, JavaScript, authenticate, connect, sign, accounts, wallet, dapp]
4+
toc_max_heading_level: 3
45
---
56

67
# Authenticate users
@@ -11,6 +12,7 @@ With the SDK, you can:
1112

1213
- **Connect users' wallets** to your dapp.
1314
- **Access user accounts** (addresses).
15+
- [**Connect and sign**](#connect-and-sign) in a single user interaction.
1416
- **Handle connection states** (connected/disconnected).
1517
- **Listen for account changes** in real time.
1618
- **Manage wallet sessions** (connect/disconnect).
@@ -125,6 +127,15 @@ async function connectWallet() {
125127
}
126128
}
127129

130+
// Disconnect wallet
131+
async function disconnectWallet() {
132+
try {
133+
await MMSDK.terminate()
134+
} catch (err) {
135+
console.error("Error with disconnecting:", err)
136+
}
137+
}
138+
128139
// Handle account changes
129140
provider.on("accountsChanged", (accounts) => {
130141
if (accounts.length === 0) {
@@ -151,6 +162,43 @@ Display connect and disconnect buttons in HTML:
151162
</div>
152163
```
153164

165+
### Connect and sign
166+
167+
If you're not using Wagmi, you can access MetaMask SDK's [`connectAndSign`](../reference/sdk-methods.md#connectandsign) method,
168+
which requests wallet access and signs the message in a single user interaction.
169+
For example:
170+
171+
```js
172+
import { MetaMaskSDK } from "@metamask/sdk"
173+
174+
const MMSDK = new MetaMaskSDK()
175+
const provider = MMSDK.getProvider()
176+
177+
async function handleConnectAndSign() {
178+
try {
179+
const signature = await MMSDK.connectAndSign({ msg: "Hello in one go!" })
180+
console.log("Signature:", signature)
181+
} catch (err) {
182+
console.error("Error with connectAndSign:", err)
183+
}
184+
}
185+
186+
document
187+
.getElementById("connectSignBtn")
188+
.addEventListener("click", handleConnectAndSign)
189+
```
190+
191+
The following HTML displays a **Connect & Sign** button:
192+
193+
```html
194+
<button id="connectSignBtn">Connect & Sign</button>
195+
```
196+
197+
:::tip
198+
This one-step flow is unique to MetaMask SDK's `connectAndSign` method.
199+
It's not part of Wagmi or other wallet libraries.
200+
:::
201+
154202
## Best practices
155203

156204
Follow these best practices when authenticating users.

sdk/guides/advanced/batch-requests.md renamed to sdk/guides/batch-requests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: Batch multiple JSON-RPC requests using MetaMask SDK or Wagmi.
3+
keywords: [SDK, Wagmi, batch, JSON-RPC, RPC, requests, methods, dapp]
34
---
45

56
# Batch requests

sdk/guides/handle-transactions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: Handle transactions with the SDK in your Wagmi or Vanilla JavaScript dapp.
3+
keywords: [SDK, Wagmi, JavaScript, send, transaction, transactions, status, estimate, gas, dapp]
34
toc_max_heading_level: 2
45
---
56

sdk/guides/interact-with-contracts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: Interact with contracts with the SDK in your Wagmi or Vanilla JavaScript dapp.
3+
keywords: [SDK, Wagmi, JavaScript, read, write, smart, contract, contracts, dapp]
34
sidebar_label: Interact with contracts
45
toc_max_heading_level: 2
56
---

sdk/guides/manage-networks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: Manage networks with the SDK in your Wagmi or Vanilla JavaScript dapp.
3+
keywords: [SDK, Wagmi, JavaScript, detect, switch, add, network, networks, dapp]
34
toc_max_heading_level: 2
45
---
56

sdk/guides/advanced/production-readiness.md renamed to sdk/guides/production-readiness.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: MetaMask-specific production readiness checklist for dapps using MetaMask SDK.
3+
keywords: [SDK, production, readiness, checklist, compatibility, errors, dapp]
34
toc_max_heading_level: 2
45
---
56

sdk/guides/use-deeplinks.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
description: Use deeplinks to connect to users' mobile wallets.
2+
description: Use deeplinks to connect to users' MetaMask mobile wallets.
3+
keywords: [SDK, deeplink, deeplinks, mobile, dapp]
34
toc_max_heading_level: 2
45
---
56

0 commit comments

Comments
 (0)