Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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
{% endhint %}

## 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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 %}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

<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>
## 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();
```