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, 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.

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 (from incoming payment)

Section titled “Create a quote with an incomingAmount (from incoming payment)”

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

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

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

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