Skip to content

Commit

Permalink
SDK update metamask_batch docs (#1610)
Browse files Browse the repository at this point in the history
* chore: updates metamask_batch rpc documentation

* chore: updates MMSDK to latest

* edit context

---------

Co-authored-by: Alexandra Tran <[email protected]>
Co-authored-by: Alexandra Carrillo <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent a0b1ccc commit 67e0fa3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@metamask/design-tokens": "^1.11.1",
"@metamask/docusaurus-openrpc": "^0.4.1",
"@metamask/profile-sync-controller": "^0.6.0",
"@metamask/sdk": "^0.28.1",
"@metamask/sdk": "^0.29.0",
"@rjsf/core": "^5.18.4",
"@rjsf/utils": "^5.18.4",
"@rjsf/validator-ajv8": "^5.18.4",
Expand Down
33 changes: 17 additions & 16 deletions wallet/how-to/use-sdk/javascript/batch-json-rpc-requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ tags:

# Batch JSON-RPC requests

You can batch multiple JSON-RPC requests using [MetaMask SDK](../../../concepts/sdk/index.md).

The SDK's `metamask_batch` method enables you to batch multiple JSON-RPC requests in a single call,
providing a streamlined approach for dapps to interact with EVM networks, and enabling complex
You can batch multiple JSON-RPC requests in a single RPC call using MetaMask SDK.
This feature enables dapps to interact with EVM networks in a streamlined way, and enables complex
sequences of actions.
This method enhances performance, usability, and efficiency by reducing the number of network calls
made to MetaMask.
It enhances performance, usability, and efficiency by reducing the number of network calls made to MetaMask.

Use cases include:
Use cases for batching requests include:

- **Batching multiple signatures** - Send multiple signing requests in one batch.

- **Switching networks** - Switch the EVM network, perform an action such as sending a transaction,
and switch back, all in one batch.

- **Mixed transactions and signatures** - Combine transaction sending and signing requests in one batch.

`metamask_batch` opens up additional possibilities for sophisticated transaction flows in dapps,
This feature opens up additional possibilities for sophisticated transaction flows in dapps,
enhancing the user experience and operational efficiency.

## Prerequisites
Expand All @@ -33,7 +28,7 @@ enhancing the user experience and operational efficiency.

## Use the `metamask_batch` method

`metamask_batch` takes an array of JSON-RPC requests (`ChainRPC[]`) as its parameter.
The SDK provides the `metamask_batch` method, which takes an array of JSON-RPC requests (`ChainRPC[]`) as its parameter.

Each request in the batch is independent.
The user receives a prompt for each action within the batch, allowing them to approve or reject
Expand All @@ -50,7 +45,7 @@ The following is an example of using `metamask_batch` to batch
[`eth_sendTransaction`](/wallet/reference/eth_sendtransaction) in React, Next.js, or React Native/Expo:

```javascript title="index.js"
import { metamask_batch } from "metamask-sdk"
import { MetaMaskSDK } from "@metamask/sdk";

function MyComponent() {
const handleBatchRequest = async () => {
Expand All @@ -67,7 +62,10 @@ function MyComponent() {
]

try {
const results = await metamask_batch(batchRequests)
const results = await provider.request({
method: "metamask_batch",
params: batchRequests
});
console.log(results) // Process results.
} catch (error) {
console.error("Batch request failed", error)
Expand All @@ -84,9 +82,9 @@ The following is an example of using `metamask_batch` to batch
[`personal_sign`](/wallet/reference/personal_sign) and
[`eth_sendTransaction`](/wallet/reference/eth_sendtransaction) in Vue.js:

```javascript title="App.vue"
```javascript title="index.vue"
<script>
import { metamask_batch } from "metamask-sdk";
import { MetaMaskSDK } from "@metamask/sdk";

export default {
methods: {
Expand All @@ -104,7 +102,10 @@ export default {
];

try {
const results = await metamask_batch(batchRequests);
const results = await provider.request({
method: "metamask_batch",
params: batchRequests
});
console.log(results);
} catch (error) {
console.error("Error in batch request", error);
Expand Down

0 comments on commit 67e0fa3

Please sign in to comment.