forked from RequestNetwork/requestNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpay-eth-request.ts
More file actions
22 lines (18 loc) · 775 Bytes
/
pay-eth-request.ts
File metadata and controls
22 lines (18 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { hasSufficientFunds, payRequest } from '@requestnetwork/payment-processor';
import { RequestNetwork } from '@requestnetwork/request-client.js';
import { Wallet } from 'ethers';
/* eslint-disable @typescript-eslint/no-floating-promises */
// for demo purpose
const wallet = Wallet.createRandom();
const requestNetwork = new RequestNetwork();
// eslint-disable-next-line
(async () => {
const account = wallet.address;
const request = await requestNetwork.fromRequestId('REQUEST_ID');
const requestData = request.getData();
if (!(await hasSufficientFunds({ request: requestData, address: account }))) {
throw new Error('You do not have enough funds to pay this request');
}
const tx = await payRequest(requestData, wallet);
await tx.wait(1);
})();