Skip to content
GitHub

Create a quote

A quote is a commitment from an account servicing entity to deliver a particular amount to a recipient when sending a particular amount from a sender. Once an authorized client obtains the requisite grant from the authorization server of the sender’s ASE Account servicing entity , the client can create a quote resource against the sender’s wallet address. The quote indicates how much it will cost the sender to proceed with the transaction.

Before you begin

We recommend creating a wallet account on the test wallet. Creating an account allows you to test your client against the Open Payments APIs by using an ILP-enabled wallet funded with play money.

Create a quote with an incomingAmount

This code snippet allows a client to create a quote with an incomingAmount when it is specified in the INCOMING_PAYMENT_URL.

Prerequisites
  • Node 20 or higher
  • A package manager such as NPM or PNPM
  • Open Payments SDK

  • TSX

    Additional configuration
  1. Add "type": "module" to package.json.
  2. Add the following to tsconfig.json
    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
    }
    }
  3. Import createAuthenticatedClient from the Open Payments SDK.

    Import dependencies

    import { createAuthenticatedClient } from "@interledger/open-payments";
    Copied!
  4. Create an authenticated Open Payments client by providing the following properties:
    • walletAddressURL : your Open Payments-enabled wallet address that your client will use to authenticate itself to one or more authorization servers.
    • privateKey : the EdDSA-Ed25519 key or preferably the absolute or relative file path to the key that’s bound to your wallet address. A public key signed with this private key must be made available as a public JWK document at {walletAddressUrl}/jwks.json url.
    • keyId : the identifier of the private key and the corresponding public key.

      Initialize Open Payments client

      const client = await createAuthenticatedClient({
        walletAddressUrl: WALLET_ADDRESS,
        privateKey: PRIVATE_KEY_PATH,
        keyId: KEY_ID,
      });
      Copied!

Get started

Import dependencies

import { createAuthenticatedClient } from "@interledger/open-payments";
Copied!

Initialize Open Payments client

const client = await createAuthenticatedClient({
  walletAddressUrl: WALLET_ADDRESS,
  privateKey: PRIVATE_KEY_PATH,
  keyId: KEY_ID,
});
Copied!

Create quote

const quote = await client.quote.create(
  {
    url: new URL(WALLET_ADDRESS).origin,
    accessToken: QUOTE_ACCESS_TOKEN,
  },
  {
    method: "ilp",
    walletAddress: WALLET_ADDRESS,
    receiver: INCOMING_PAYMENT_URL,
  },
);
Copied!

Output

console.log("QUOTE_URL =", quote.id);
Copied!

Run tsx path/to/directory/index.ts.

View full source

Create a quote with a debit amount

This code snippet allows a client to create a quote with a debitAmount, which specifies the amount that will be deducted from the sender’s wallet.

Prerequisites
  • Node 20 or higher
  • A package manager such as NPM or PNPM
  • Open Payments SDK

  • TSX

    Additional configuration
  1. Add "type": "module" to package.json.
  2. Add the following to tsconfig.json
    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
    }
    }
  3. Import createAuthenticatedClient from the Open Payments SDK.

    Import dependencies

    import { createAuthenticatedClient } from "@interledger/open-payments";
    Copied!
  4. Create an authenticated Open Payments client by providing the following properties:
    • walletAddressURL : your Open Payments-enabled wallet address that your client will use to authenticate itself to one or more authorization servers.
    • privateKey : the EdDSA-Ed25519 key or preferably the absolute or relative file path to the key that’s bound to your wallet address. A public key signed with this private key must be made available as a public JWK document at {walletAddressUrl}/jwks.json url.
    • keyId : the identifier of the private key and the corresponding public key.

      Initialize Open Payments client

      const client = await createAuthenticatedClient({
        walletAddressUrl: WALLET_ADDRESS,
        privateKey: PRIVATE_KEY_PATH,
        keyId: KEY_ID,
      });
      Copied!

Get started

Import dependencies

import { createAuthenticatedClient } from "@interledger/open-payments";
Copied!

Initialize Open Payments client

const client = await createAuthenticatedClient({
  walletAddressUrl: WALLET_ADDRESS,
  privateKey: PRIVATE_KEY_PATH,
  keyId: KEY_ID,
});
Copied!

Get wallet address information

const walletAddress = await client.walletAddress.get({
  url: WALLET_ADDRESS,
});
Copied!

Create quote with debit amount

const quote = await client.quote.create(
  {
    url: new URL(WALLET_ADDRESS).origin,
    accessToken: QUOTE_ACCESS_TOKEN,
  },
  {
    method: "ilp",
    walletAddress: WALLET_ADDRESS,
    receiver: INCOMING_PAYMENT_URL,
    debitAmount: {
      value: "500",
      assetCode: walletAddress.assetCode,
      assetScale: walletAddress.assetScale,
    },
  },
);
Copied!

Output

console.log("QUOTE_URL =", quote.id);
Copied!

Run tsx path/to/directory/index.ts.

View full source

Create a quote with a receive amount

This code snippet allows a client to create a quote with a receiveAmount, which specifies the amount that the recipient’s wallet will receive.

Prerequisites
  • Node 20 or higher
  • A package manager such as NPM or PNPM
  • Open Payments SDK

  • TSX

    Additional configuration
  1. Add "type": "module" to package.json.
  2. Add the following to tsconfig.json
    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
    }
    }
  3. Import createAuthenticatedClient from the Open Payments SDK.

    Import dependencies

    import { createAuthenticatedClient } from "@interledger/open-payments";
    Copied!
  4. Create an authenticated Open Payments client by providing the following properties:
    • walletAddressURL : your Open Payments-enabled wallet address that your client will use to authenticate itself to one or more authorization servers.
    • privateKey : the EdDSA-Ed25519 key or preferably the absolute or relative file path to the key that’s bound to your wallet address. A public key signed with this private key must be made available as a public JWK document at {walletAddressUrl}/jwks.json url.
    • keyId : the identifier of the private key and the corresponding public key.

      Initialize Open Payments client

      const client = await createAuthenticatedClient({
        walletAddressUrl: WALLET_ADDRESS,
        privateKey: PRIVATE_KEY_PATH,
        keyId: KEY_ID,
      });
      Copied!

Get started

Import dependencies

import { createAuthenticatedClient } from "@interledger/open-payments";
Copied!

Initialize Open Payments client

const client = await createAuthenticatedClient({
  walletAddressUrl: WALLET_ADDRESS,
  privateKey: PRIVATE_KEY_PATH,
  keyId: KEY_ID,
});
Copied!

Get wallet address information

const walletAddress = await client.walletAddress.get({
  url: WALLET_ADDRESS,
});
Copied!

Create quote with receive amount

const quote = await client.quote.create(
  {
    url: new URL(WALLET_ADDRESS).origin,
    accessToken: QUOTE_ACCESS_TOKEN,
  },
  {
    method: "ilp",
    walletAddress: WALLET_ADDRESS,
    receiver: INCOMING_PAYMENT_URL,
    receiveAmount: {
      value: "500",
      assetCode: walletAddress.assetCode,
      assetScale: walletAddress.assetScale,
    },
  },
);
Copied!

Output

console.log("QUOTE_URL =", quote.id);
Copied!

Run tsx path/to/directory/index.ts.

View full source

References