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
Section titled “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
Section titled “Create a quote with an incomingAmount”This code snippet allows a client to create a quote with an incomingAmount
when one is specified in the INCOMING_PAYMENT_URL
.
Initial configuration
If you’re using JavaScript, only do the first step.
- Add
"type": "module"
topackage.json
. - Add the following to
tsconfig.json
{"compilerOptions": {"target": "ES2022","module": "ES2022"}}
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! 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
Import dependencies
use OpenPayments\AuthClient;
use OpenPayments\Config\Config;
Copied! Initialize Open Payments client
$config = new Config($WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);
$opClient = new AuthClient($config);
Copied! Create quote
$newQuote = $opClient->quote()->create(
[
"url" => $wallet->resourceServer,
"access_token" => $QUOTE_GRANT_ACCESS_TOKEN,
],
[
"method" => "ilp",
"walletAddress" => $wallet->id,
"receiver" => $INCOMING_PAYMENT_URL,
]
);
Copied! Output
$output->writeln("QUOTE_URL " . $newQuote->id);
Copied! Create a quote with a debit amount
Section titled “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.
Initial configuration
If you’re using JavaScript, only do the first step.
- Add
"type": "module"
topackage.json
. - Add the following to
tsconfig.json
{"compilerOptions": {"target": "ES2022","module": "ES2022"}}
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! 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
Import dependencies
use OpenPayments\AuthClient;
use OpenPayments\Config\Config;
Copied! Initialize Open Payments client
$config = new Config($WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);
$opClient = new AuthClient($config);
Copied! Get wallet address information
$wallet = $opClient->walletAddress()->get([
"url" => $config->getWalletAddressUrl(),
]);
Copied! Create quote with debit amount
$newQuote = $opClient->quote()->create(
[
"url" => $wallet->resourceServer,
"access_token" => $QUOTE_GRANT_ACCESS_TOKEN,
],
[
"method" => "ilp",
"walletAddress" => $wallet->id,
"receiver" => $INCOMING_PAYMENT_URL,
"debitAmount" => [
"assetCode" => $wallet->assetCode,
"assetScale" => $wallet->assetScale,
"value" => "130",
],
]
);
Copied! Output
$output->writeln("QUOTE_URL " . $newQuote->id);
Copied! Create a quote with a receive amount
Section titled “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.
Initial configuration
If you’re using JavaScript, only do the first step.
- Add
"type": "module"
topackage.json
. - Add the following to
tsconfig.json
{"compilerOptions": {"target": "ES2022","module": "ES2022"}}
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! 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
Import dependencies
use OpenPayments\AuthClient;
use OpenPayments\Config\Config;
Copied! Initialize Open Payments client
$config = new Config($WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);
$opClient = new AuthClient($config);
Copied! Get wallet address information
$wallet = $opClient->walletAddress()->get([
"url" => $config->getWalletAddressUrl(),
]);
Copied! Create quote with receive amount
$newQuote = $opClient->quote()->create(
[
"url" => $wallet->resourceServer,
"access_token" => $QUOTE_GRANT_ACCESS_TOKEN,
],
[
"method" => "ilp",
"walletAddress" => $wallet->id,
"receiver" => $INCOMING_PAYMENT_URL,
"receiveAmount" => [
"assetCode" => $wallet->assetCode,
"assetScale" => $wallet->assetScale,
"value" => "130",
],
]
);
Copied! Output
$output->writeln("QUOTE_URL " . $newQuote->id);
Copied!