Using Request client js library

You can use the Request Client library to connect to an existing node, for example one you have deployed yourself. You can view an interactive example of using the request client below.

The request client ships both as a commonjs and a UMD module. This means you can use it in node application and in web pages.

Below is an example of using the request-client.js as a commonjs module.

Using the request-client.js library

@requestnetwork/request-client.js is a typescript library part of the Request protocol. This package allows you to interact with the Request blockchain through Request nodes. This client side library uses Request nodes as servers, connected in HTTP. See the Request node documentation for more details on their API. It ships both as a commonjs and a UMD module. This means you can use it in node application and in web pages.

Use @requestnetwork/request-client.js to connect to a node and create requests.

Installing in nodeJS

npm install @requestnetwork/request-client.js


import { RequestNetwork } from '@requestnetwork/request-client.js'
const RequestNetwork = require('@requestnetwork/request-client.js');

Including in Web Application

<!-- This exposes the library as a global variable: RequestNetwork -->
<script src=""

For more information you can check the request-client.js documentation or our github repo.

You can also follow this example.

Configure the Node to be used

Connect the library to a node or mock a node for development environments like explained here.

const requestNetwork = new RequestNetwork({
nodeConnectionConfig: { baseURL: '' },

It can be further configured with option from Axios.

Alternatively, you can use the request-client in development without a node by using the useMockStorage option. When the option useMockStorage is true, the library will use a mock storage in memory instead of a Request node. It is meant to simplify local development and should never be used in production. Nothing will be persisted on the Ethereum blockchain and IPFS, it will all stay in memory until your program stops.

const requestNetwork = new RequestNetwork({ useMockStorage: true });

That's it! You can now use the Request client.

The request-client.js in practice

Let's create a simple application using the request-client.js. We'll create a simple invoice flow between two parties which will include creating, accepting, fetching and updating the expected amount of the invoice.

Firstly, we need to define some parameters for the invoice such as the currency, expected amounts, the payee

const requestParameters = {
currency: 'BTC',
expectedAmount: '100000000000',
payee: {
type: RequestNetwork.Types.Identity.TYPE.ETHEREUM_ADDRESS,
value: '0x627306090abab3a6e1400e9345bc60c78a8bef57',
payer: {
type: RequestNetwork.Types.Identity.TYPE.ETHEREUM_ADDRESS,
value: '0x740fc87Bd3f41d07d23A01DEc90623eBC5fed9D6',

We will also need to define a payment network which will define which payment address will receive the BTC payment (see payment detection)

const paymentNetwork = {
parameters: {
paymentAddress: 'mgPKDuVmuS9oeE2D9VPiCQriyU14wxWS1v',

We now have everything we need to create an invoice, we can create an invoice like so:

const invoice = await requestNetwork.createRequest({
signer: requestParameters.payee,

You can now view information on this request

Get invoice information from its request ID

const invoiceFromRequestID = await requestNetwork.fromRequestId(invoice);
const requestData = invoiceFromRequestID.getData();
/* {
} */

We can then use this object to check various fields of the request like expectedAmount, balance, payer, payee, and metadata attached to the request.

Accepting / cancelling an invoice information

After the invoice has been created, the customer can accept the invoice. First you must create a signature as per - after this you can accept, decline or change the expected amount of the invoice

await request.accept(signatureInfo);
await request.cancel(signatureInfo);
//Increase the expected amount
await request.decreaseExpectedAmountRequest(amount, signatureInfo);
//Decrease the expected amount
await request.increaseExpectedAmountRequest(amount, signatureInfo);

Don't forget, we can then call fromRequestId to get the updated invoice information.

Signing transactions

Transactions are signed through Signature Providers. Today, the providers available for use are:


A request can be encrypted. To manipulate encrypted request you need a Decryption Provider, e.g:

Create an encrypted request

Ethereum Private Key Decryption Provider:

import EPKDecryptionProvider from '@requestnetwork/epk-decryption'
const decryptionProvider = new EPKDecryptionProvider({
key: '0x4025da5692759add08f98f4b056c41c71916a671cedc7584a80d73adc7fb43c0',
method: RequestNetwork.Types.Encryption.METHOD.ECIES,
const requestNetwork = new RequestNetwork({
useMockStorage: true

Then you can create an encrypted request:

const payeeEncryptionPublicKey = {
key: 'cf4a1d0bbef8bf0e3fa479a9def565af1b22ea6266294061bfb430701b54a83699e3d47bf52e9f0224dcc29a02721810f1f624f1f70ea3cc5f1fb752cfed379d',
method: RequestNetwork.Types.Encryption.METHOD.ECIES,
const payerEncryptionPublicKey = {
key: '299708c07399c9b28e9870c4e643742f65c94683f35d1b3fc05d0478344ee0cc5a6a5e23f78b5ff8c93a04254232b32350c8672d2873677060d5095184dad422',
method: RequestNetwork.Types.Encryption.METHOD.ECIES,
const invoice = await requestNetwork._createEncryptedRequest({
signer: requestParameters.payee,
[payeeEncryptionPublicKey, payerEncryptionPublicKey]

Note: you decryption provider must be able to decrypt the request. Otherwise an error will be trigger after the creation.

Get invoice information from its request ID

Like a clear request you will be able to get it from its request id a request. You just need to have a decryption provider that can decrypt the request.

Accepting / cancelling an invoice information

Like a clear request you will be able to update a request. You just need to have a decryption provider that can decrypt the request.