diff --git a/docs/advanced/request-network-sdk/get-started/quickstart-node.js.md b/docs/advanced/request-network-sdk/get-started/quickstart-node.js.md index a1ed903..13ada9e 100644 --- a/docs/advanced/request-network-sdk/get-started/quickstart-node.js.md +++ b/docs/advanced/request-network-sdk/get-started/quickstart-node.js.md @@ -8,7 +8,7 @@ This approach works well for Node.js environments _without_ access to a Web3 wal You will learn: * How to create a request -* How to update a request (coming soon...) +* How to update a request * How to pay a request * How to detect a payment * How to retrieve a user’s requests @@ -16,7 +16,7 @@ You will learn: ## Repository -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) +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) ## Create a request @@ -127,6 +127,23 @@ Altogether it looks like this: {% @github-files/github-code-block url="https://github.com/RequestNetwork/quickstart-node-js/blob/main/src/createRequest.js" %} +## Update a request + +After creating a request, you might need to update it (e.g., to cancel it or adjust the amount). Updates require a `signatureProvider`. + +```javascript +const request = await requestClient.fromRequestId('YOUR_REQUEST_ID'); + +// Payer accepts the request +await request.accept({ + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, + value: payerIdentity, +}); +await request.waitForConfirmation(); +``` + +See the [Updating a Request](../sdk-guides/request-client/updating-a-request.md) guide for more details. + ## Pay a request / Detect a payment 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( {% endtab %} {% tab title="viem" %} -Coming soon. Probably involves `publicClientToProvider()` and `walletClientToSigner()`. +In Node.js with a private key, use ethers v5 directly (see tab above). + +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. {% endtab %} {% endtabs %} diff --git a/docs/advanced/request-network-sdk/sdk-guides/request-client/updating-a-request.md b/docs/advanced/request-network-sdk/sdk-guides/request-client/updating-a-request.md index fb0aa83..9b133f1 100644 --- a/docs/advanced/request-network-sdk/sdk-guides/request-client/updating-a-request.md +++ b/docs/advanced/request-network-sdk/sdk-guides/request-client/updating-a-request.md @@ -1,7 +1,89 @@ # Updating a Request -After a request is created, it can be updated: +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. -
NameDescriptionRole Authorized
acceptaccept a request, indicating that it will be paidpayer
cancelcancel a requestpayee, payer
reduceExpectedAmountreduce the expected amountpayee
increaseExpectedAmountincrease the expected amountpayer
addStakeholdersgrant 1 or more third parties access to view an encrypted requestpayee, payer, third party
+## Summary of Actions -Feature exists. More docs coming soon... +| Action | Description | Authorized Role | +| :--- | :--- | :--- | +| **accept** | Accept a request, indicating that it will be paid | Payer | +| **cancel** | Cancel a request | Payee or Payer | +| **reduceExpectedAmount** | Reduce the expected amount | Payee | +| **increaseExpectedAmount** | Increase the expected amount | Payer | +| **addStakeholders** | Grant 1 or more third parties access to view an encrypted request | Payee, Payer, or Third Party | + +## Examples + +### Initialize the Request Client + +First, retrieve the request you want to update. You must provide a `signatureProvider` to sign the update transactions. + +```javascript +const { RequestNetwork, Types } = require("@requestnetwork/request-client.js"); + +const requestClient = new RequestNetwork({ + nodeConnectionConfig: { baseURL: "https://sepolia.gateway.request.network/" }, + signatureProvider: epkSignatureProvider, // Required for updates +}); + +const request = await requestClient.fromRequestId('YOUR_REQUEST_ID'); +``` + +### Accept a Request (Payer) + +The payer can accept a request to signal their intention to pay. + +```javascript +const updatedRequestData = await request.accept({ + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, + value: payerIdentity, +}); + +// Wait for the update to be persisted +await request.waitForConfirmation(); +``` + +### Cancel a Request (Payee or Payer) + +Either the payee or the payer can cancel a request. + +```javascript +const updatedRequestData = await request.cancel({ + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, + value: signerIdentity, +}); + +await request.waitForConfirmation(); +``` + +### Increase Expected Amount (Payer) + +The payer can increase the expected amount (e.g., adding a tip or adjusting for additional services). + +```javascript +const updatedRequestData = await request.increaseExpectedAmountRequest( + '100000000000000000', // Amount to add in base units (e.g., 0.1 ETH) + { + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, + value: payerIdentity, + } +); + +await request.waitForConfirmation(); +``` + +### Reduce Expected Amount (Payee) + +The payee can reduce the expected amount (e.g., applying a discount). + +```javascript +const updatedRequestData = await request.reduceExpectedAmountRequest( + '100000000000000000', // Amount to subtract in base units + { + type: Types.Identity.TYPE.ETHEREUM_ADDRESS, + value: payeeIdentity, + } +); + +await request.waitForConfirmation(); +```