Skip to content
GitHub

Create a quote

The Create Quote API lets you request the creation of a quote resource against the sender’s wallet address.

A quote is a commitment from an account servicing entity to pay a particular amount from the sender’s account or pay a particular amount into the recipient’s account, depending on the quote type. A quote is only valid for a limited time.

The code snippets below let an authorized client request a quote from an incomingAmount, with a debit amount, or with a receive amount. You can read more about these quote types on the Resources page.

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.

Authenticated client required

Create this type of quote when the incoming payment resource already has a defined incomingAmount.

Prerequisites
Initial configuration

If you’re using JavaScript, only do the first step.

  1. Add "type": "module" to package.json.

  2. Add the following to tsconfig.json

    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
    }
    }
// Import dependencies
import { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize client
const client = await createAuthenticatedClient({
walletAddressUrl: WALLET_ADDRESS,
privateKey: PRIVATE_KEY_PATH,
keyId: KEY_ID
})
// Get wallet address information
const walletAddress = await client.walletAddress.get({
url: WALLET_ADDRESS
})
// Create quote
const quote = await client.quote.create(
{
url: walletAddress.resourceServer,
accessToken: QUOTE_ACCESS_TOKEN
},
{
method: 'ilp',
walletAddress: WALLET_ADDRESS,
receiver: INCOMING_PAYMENT_URL
}
)
// Output
console.log('QUOTE_URL =', quote.id)

For TypeScript, run tsx path/to/directory/index.ts. View full TS source

For JavaScript, run node path/to/directory/index.js. View full JS source

Authenticated client required

Create this type of quote to specify a debit amount. The debit amount is the amount to deduct from the sender’s wallet.

Prerequisites
Initial configuration

If you’re using JavaScript, only do the first step.

  1. Add "type": "module" to package.json.

  2. Add the following to tsconfig.json

    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
    }
    }
// Import dependencies
import { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize client
const client = await createAuthenticatedClient({
walletAddressUrl: WALLET_ADDRESS,
privateKey: PRIVATE_KEY_PATH,
keyId: KEY_ID
})
// Get wallet address information
const walletAddress = await client.walletAddress.get({
url: WALLET_ADDRESS
})
// Create quote with debit amount
const quote = await client.quote.create(
{
url: walletAddress.resourceServer,
accessToken: QUOTE_ACCESS_TOKEN
},
{
method: 'ilp',
walletAddress: WALLET_ADDRESS,
receiver: INCOMING_PAYMENT_URL,
debitAmount: {
value: '500',
assetCode: walletAddress.assetCode,
assetScale: walletAddress.assetScale
}
}
)
// Output
console.log('QUOTE_URL =', quote.id)

For TypeScript, run tsx path/to/directory/index.ts. View full TS source

For JavaScript, run node path/to/directory/index.js. View full JS source

Authenticated client required

Create this type of quote to specify a receive amount. The receive amount is the amount that will be paid into the recipient’s wallet.

Prerequisites
Initial configuration

If you’re using JavaScript, only do the first step.

  1. Add "type": "module" to package.json.

  2. Add the following to tsconfig.json

    {
    "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022"
    }
    }
// Import dependencies
import { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize client
const client = await createAuthenticatedClient({
walletAddressUrl: WALLET_ADDRESS,
privateKey: PRIVATE_KEY_PATH,
keyId: KEY_ID
})
// Get wallet address information
const walletAddress = await client.walletAddress.get({
url: WALLET_ADDRESS
})
// Create quote with receive amount
const quote = await client.quote.create(
{
url: walletAddress.resourceServer,
accessToken: QUOTE_ACCESS_TOKEN
},
{
method: 'ilp',
walletAddress: WALLET_ADDRESS,
receiver: INCOMING_PAYMENT_URL,
receiveAmount: {
value: '500',
assetCode: walletAddress.assetCode,
assetScale: walletAddress.assetScale
}
}
)
// Output
console.log('QUOTE_URL =', quote.id)

For TypeScript, run tsx path/to/directory/index.ts. View full TS source

For JavaScript, run node path/to/directory/index.js. View full JS source