Skip to content

Commit 5df5fe3

Browse files
AllenAJMantisCloneclaude
authored
docs: update SDK quickstart and request update guide (#134)
Co-authored-by: MantisClone <david.huntmateo@request.network> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b303612 commit 5df5fe3

File tree

2 files changed

+107
-6
lines changed

2 files changed

+107
-6
lines changed

docs/advanced/request-network-sdk/get-started/quickstart-node.js.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ This approach works well for Node.js environments _without_ access to a Web3 wal
88
You will learn:
99

1010
* How to create a request
11-
* How to update a request (coming soon...)
11+
* How to update a request
1212
* How to pay a request
1313
* How to detect a payment
1414
* How to retrieve a user’s requests
1515
{% endhint %}
1616

1717
## Repository
1818

19-
All of the following examples can be found in this repository [https://github.com/RequestNetwork/quickstart-node.js](https://github.com/RequestNetwork/quickstart-node.js)
19+
All of the following examples can be found in this repository [https://github.com/RequestNetwork/quickstart-node-js](https://github.com/RequestNetwork/quickstart-node-js)
2020

2121
## Create a request
2222

@@ -127,6 +127,23 @@ Altogether it looks like this:
127127

128128
{% @github-files/github-code-block url="https://github.com/RequestNetwork/quickstart-node-js/blob/main/src/createRequest.js" %}
129129

130+
## Update a request
131+
132+
After creating a request, you might need to update it (e.g., to cancel it or adjust the amount). Updates require a `signatureProvider`.
133+
134+
```javascript
135+
const request = await requestClient.fromRequestId('YOUR_REQUEST_ID');
136+
137+
// Payer accepts the request
138+
await request.accept({
139+
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
140+
value: payerIdentity,
141+
});
142+
await request.waitForConfirmation();
143+
```
144+
145+
See the [Updating a Request](../sdk-guides/request-client/updating-a-request.md) guide for more details.
146+
130147
## Pay a request / Detect a payment
131148

132149
First, construct a `RequestNetwork` object and connect it to a Request Node. In this example, we use the Sepolia Request Node Gateway:
@@ -171,7 +188,9 @@ const payerWallet = new Wallet(
171188
{% endtab %}
172189

173190
{% tab title="viem" %}
174-
Coming soon. Probably involves `publicClientToProvider()` and `walletClientToSigner()`.
191+
In Node.js with a private key, use ethers v5 directly (see tab above).
192+
193+
The viem-to-ethers adapter patterns in the [Browser Quickstart](quickstart-browser.md) are designed for browser wallets with EIP-1193 interfaces. In Node.js, simply create an ethers `JsonRpcProvider` and `Wallet` from your RPC URL and private key.
175194
{% endtab %}
176195
{% endtabs %}
177196

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,89 @@
11
# Updating a Request
22

3-
After a request is created, it can be updated:
3+
After a request is created, it can be updated by the authorized parties. Each update requires a signature and is persisted to the Request Network.
44

5-
<table data-full-width="true"><thead><tr><th>Name</th><th>Description</th><th>Role Authorized</th></tr></thead><tbody><tr><td><strong>accept</strong></td><td>accept a request, indicating that it will be paid</td><td>payer</td></tr><tr><td><strong>cancel</strong></td><td>cancel a request</td><td>payee, payer</td></tr><tr><td><strong>reduceExpectedAmount</strong></td><td>reduce the expected amount</td><td>payee</td></tr><tr><td><strong>increaseExpectedAmount</strong></td><td>increase the expected amount</td><td>payer</td></tr><tr><td><strong>addStakeholders</strong></td><td>grant 1 or more third parties access to view an encrypted request</td><td>payee, payer, third party</td></tr></tbody></table>
5+
## Summary of Actions
66

7-
Feature exists. More docs coming soon...
7+
| Action | Description | Authorized Role |
8+
| :--- | :--- | :--- |
9+
| **accept** | Accept a request, indicating that it will be paid | Payer |
10+
| **cancel** | Cancel a request | Payee or Payer |
11+
| **reduceExpectedAmount** | Reduce the expected amount | Payee |
12+
| **increaseExpectedAmount** | Increase the expected amount | Payer |
13+
| **addStakeholders** | Grant 1 or more third parties access to view an encrypted request | Payee, Payer, or Third Party |
14+
15+
## Examples
16+
17+
### Initialize the Request Client
18+
19+
First, retrieve the request you want to update. You must provide a `signatureProvider` to sign the update transactions.
20+
21+
```javascript
22+
const { RequestNetwork, Types } = require("@requestnetwork/request-client.js");
23+
24+
const requestClient = new RequestNetwork({
25+
nodeConnectionConfig: { baseURL: "https://sepolia.gateway.request.network/" },
26+
signatureProvider: epkSignatureProvider, // Required for updates
27+
});
28+
29+
const request = await requestClient.fromRequestId('YOUR_REQUEST_ID');
30+
```
31+
32+
### Accept a Request (Payer)
33+
34+
The payer can accept a request to signal their intention to pay.
35+
36+
```javascript
37+
const updatedRequestData = await request.accept({
38+
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
39+
value: payerIdentity,
40+
});
41+
42+
// Wait for the update to be persisted
43+
await request.waitForConfirmation();
44+
```
45+
46+
### Cancel a Request (Payee or Payer)
47+
48+
Either the payee or the payer can cancel a request.
49+
50+
```javascript
51+
const updatedRequestData = await request.cancel({
52+
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
53+
value: signerIdentity,
54+
});
55+
56+
await request.waitForConfirmation();
57+
```
58+
59+
### Increase Expected Amount (Payer)
60+
61+
The payer can increase the expected amount (e.g., adding a tip or adjusting for additional services).
62+
63+
```javascript
64+
const updatedRequestData = await request.increaseExpectedAmountRequest(
65+
'100000000000000000', // Amount to add in base units (e.g., 0.1 ETH)
66+
{
67+
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
68+
value: payerIdentity,
69+
}
70+
);
71+
72+
await request.waitForConfirmation();
73+
```
74+
75+
### Reduce Expected Amount (Payee)
76+
77+
The payee can reduce the expected amount (e.g., applying a discount).
78+
79+
```javascript
80+
const updatedRequestData = await request.reduceExpectedAmountRequest(
81+
'100000000000000000', // Amount to subtract in base units
82+
{
83+
type: Types.Identity.TYPE.ETHEREUM_ADDRESS,
84+
value: payeeIdentity,
85+
}
86+
);
87+
88+
await request.waitForConfirmation();
89+
```

0 commit comments

Comments
 (0)