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.
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 from an incoming amount
Section titled “Create a quote from an incoming amount”Create this type of quote when the incoming payment resource already has a
defined incomingAmount.
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 dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get wallet address informationconst walletAddress = await client.walletAddress.get({ url: WALLET_ADDRESS})
// Create quoteconst quote = await client.quote.create( { url: walletAddress.resourceServer, accessToken: QUOTE_ACCESS_TOKEN }, { method: 'ilp', walletAddress: WALLET_ADDRESS, receiver: INCOMING_PAYMENT_URL })
// Outputconsole.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
// Import dependenciesuse open_payments::client::api::AuthenticatedResources;use open_payments::client::utils::get_resource_server_url;use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env};use open_payments::types::{resource::CreateQuoteRequest, PaymentMethodType, Receiver};
// Initialize clientlet client = create_authenticated_client()?;
// Prepare quote requestlet access_token = get_env_var("QUOTE_ACCESS_TOKEN")?;let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?;let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?;let resource_server_url = get_resource_server_url(&wallet_address_url)?;
let request = CreateQuoteRequest::NoAmountQuote { wallet_address: wallet_address_url, receiver: Receiver(incoming_payment_url), method: PaymentMethodType::Ilp,};
// Create quoteprintln!( "Quote create request JSON: {}", serde_json::to_string_pretty(&request)?);
let quote = client .quotes() .create(&resource_server_url, &request, Some(&access_token)) .await?;
// Outputprintln!("Created quote: {quote:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
$wallet = $opClient->walletAddress()->get([ 'url' => $config->getWalletAddressUrl()]);
// Create quote$newQuote = $opClient->quote()->create( [ 'url' => $wallet->resourceServer, 'access_token' => $QUOTE_GRANT_ACCESS_TOKEN, ], [ 'method' => "ilp", 'walletAddress' => $wallet->id, 'receiver' => $INCOMING_PAYMENT_URL, ]);
// Outputecho 'QUOTE_URL ' . $newQuote->id . PHP_EOL;echo 'QUOTE ' . print_r($newQuote, true) . PHP_EOL;package main
// Import dependenciesimport ( "context" "encoding/json" "fmt" "log"
op "github.com/interledger/open-payments-go" rs "github.com/interledger/open-payments-go/generated/resourceserver")
func main() { // Initialize client client, err := op.NewAuthenticatedClient(WALLET_ADDRESS_URL, PRIVATE_KEY_BASE_64, KEY_ID) if err != nil { log.Fatalf("Error creating authenticated client: %v\n", err) }
// Create quote quote, err := client.Quote.Create(context.TODO(), op.QuoteCreateParams{ BaseURL: RESOURCE_SERVER_URL, AccessToken: QUOTE_ACCESS_TOKEN, Payload: rs.CreateQuoteJSONBody0{ WalletAddressSchema: WALLET_ADDRESS_URL, Receiver: INCOMING_PAYMENT_URL, Method: "ilp", }, }) if err != nil { log.Fatalf("Error creating quote: %v\n", err) }
// Output quoteJSON, err := json.MarshalIndent(quote, "", " ") if err != nil { log.Fatalf("Error marshaling quote: %v\n", err) } fmt.Println("QUOTE:", string(quoteJSON)) fmt.Println("QUOTE_URL:", *quote.Id)}// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;
// Initialize clientIOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet address informationvar receiverWallet = client.walletAddress().get("https://cloudninebank.example.com/merchant");var senderWallet = client.walletAddress().get("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = client.auth().grant().incomingPayment(receiverWallet);var incomingPayment = client.payment().createIncoming(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// Create quotevar quoteRequest = client.auth().grant().quote(senderWallet);var quote = client.quote().create(quoteRequest.getAccess().getToken(), senderWallet, incomingPayment, Optional.empty(), Optional.empty());
// Outputlog.info("QUOTE: {}", quote);// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;using OpenPayments.Sdk.Generated.Resource;using OpenPayments.Sdk.HttpSignatureUtils;
// Initialize clientvar client = new ServiceCollection() .UseOpenPayments(opts => { opts.UseAuthenticatedClient = true; opts.KeyId = CLIENT_ID; opts.PrivateKey = KeyUtils.LoadPem(CLIENT_SECRET); opts.ClientUrl = new Uri(CLIENT_WALLET_ADDRESS); }) .BuildServiceProvider() .GetRequiredService<IAuthenticatedClient>();
// Get wallet address informationvar waInfo = await client.GetWalletAddressAsync(WALLET_ADDRESS);
// Create quotevar quote = await client.CreateQuoteAsync( new AuthRequestArgs { Url = waInfo.ResourceServer, AccessToken = QUOTE_ACCESS_TOKEN, }, new QuoteBody { WalletAddress = waInfo.Id, Receiver = new Uri(INCOMING_PAYMENT_URL), Method = PaymentMethod.Ilp });
// OutputConsole.WriteLine($"QUOTE_URL = {quote.Id}");Create a quote with a debit amount
Section titled “Create a quote with a debit amount”Create this type of quote to specify a debit amount. The debit amount is the amount to deduct 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 dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get wallet address informationconst walletAddress = await client.walletAddress.get({ url: WALLET_ADDRESS})
// Create quote with debit amountconst 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 } })
// Outputconsole.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
// Import dependenciesuse open_payments::client::api::AuthenticatedResources;use open_payments::client::utils::get_resource_server_url;use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env};use open_payments::types::{resource::CreateQuoteRequest, Amount, PaymentMethodType, Receiver};
// Initialize clientlet client = create_authenticated_client()?;
// Create quote with debit amountlet access_token = get_env_var("QUOTE_ACCESS_TOKEN")?;let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?;let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?;let resource_server_url = get_resource_server_url(&wallet_address_url)?;
let request = CreateQuoteRequest::FixedSendAmountQuote { wallet_address: wallet_address_url, receiver: Receiver(incoming_payment_url), method: PaymentMethodType::Ilp, debit_amount: Amount { value: "1000".to_string(), asset_code: "EUR".to_string(), asset_scale: 2u8, },};
println!( "Quote create request JSON: {}", serde_json::to_string_pretty(&request)?);
let quote = client .quotes() .create(&resource_server_url, &request, Some(&access_token)) .await?;
// Outputprintln!("Created quote: {quote:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Get wallet address information$wallet = $opClient->walletAddress()->get([ 'url' => $config->getWalletAddressUrl()]);
// 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", ], ]);
// Outputecho 'QUOTE_URL ' . $newQuote->id . PHP_EOL;echo 'QUOTE ' . print_r($newQuote, true) . PHP_EOL;package main
// Import dependenciesimport ( "context" "encoding/json" "fmt" "log"
op "github.com/interledger/open-payments-go" rs "github.com/interledger/open-payments-go/generated/resourceserver")
func main() { // Initialize client client, err := op.NewAuthenticatedClient(WALLET_ADDRESS_URL, PRIVATE_KEY_BASE_64, KEY_ID) if err != nil { log.Fatalf("Error creating authenticated client: %v\n", err) }
// Get wallet address information walletAddress, err := client.WalletAddress.Get(context.TODO(), op.WalletAddressGetParams{ URL: WALLET_ADDRESS_URL, }) if err != nil { log.Fatalf("Error fetching wallet address: %v\n", err) }
// Create quote with debit amount quote, err := client.Quote.Create(context.TODO(), op.QuoteCreateParams{ BaseURL: walletAddress.ResourceServer, AccessToken: QUOTE_ACCESS_TOKEN, Payload: rs.CreateQuoteJSONBody1{ WalletAddressSchema: WALLET_ADDRESS_URL, Receiver: INCOMING_PAYMENT_URL, Method: "ilp", DebitAmount: rs.Amount{ Value: "500", AssetCode: walletAddress.AssetCode, AssetScale: walletAddress.AssetScale, }, }, }) if err != nil { log.Fatalf("Error creating quote: %v\n", err) }
// Output quoteJSON, err := json.MarshalIndent(quote, "", " ") if err != nil { log.Fatalf("Error marshaling quote: %v\n", err) } fmt.Println("QUOTE:", string(quoteJSON)) fmt.Println("QUOTE_URL:", *quote.Id)}// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;import org.interledger.openpayments.model.common.Amount;
// Initialize clientIOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet address informationvar receiverWallet = client.walletAddress().get("https://cloudninebank.example.com/merchant");var senderWallet = client.walletAddress().get("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = client.auth().grant().incomingPayment(receiverWallet);var incomingPayment = client.payment().createIncoming(receiverWallet, grantRequest, BigDecimal.valueOf(11.50));
// Create quote with debit amountvar quoteRequest = client.auth().grant().quote(senderWallet);var quote = client.quote().create(quoteRequest.getAccess().getToken(),senderWallet,incomingPayment,Optional.of(Amount.build(BigDecimal.valueOf(12.34), "USD")),// Debit Amount - Not the same as incoming payment amount.Optional.empty());
// Outputlog.info("QUOTE: {}", incomingPayment);// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;using OpenPayments.Sdk.Generated.Resource;using OpenPayments.Sdk.HttpSignatureUtils;
// Initialize clientvar client = new ServiceCollection() .UseOpenPayments(opts => { opts.UseAuthenticatedClient = true; opts.KeyId = CLIENT_ID; opts.PrivateKey = KeyUtils.LoadPem(CLIENT_SECRET); opts.ClientUrl = new Uri(CLIENT_WALLET_ADDRESS); }) .BuildServiceProvider() .GetRequiredService<IAuthenticatedClient>();
// Get wallet address informationvar waInfo = await client.GetWalletAddressAsync(WALLET_ADDRESS);
// Create quote with debit amountvar quote = await client.CreateQuoteAsync( new AuthRequestArgs { Url = waInfo.ResourceServer, AccessToken = QUOTE_ACCESS_TOKEN, }, new QuoteBody { WalletAddress = waInfo.Id, Receiver = new Uri(INCOMING_PAYMENT_URL), Method = PaymentMethod.Ilp, DebitAmount = new Amount { Value = "500", AssetCode = waInfo.AssetCode, AssetScale = waInfo.AssetScale, } });
// OutputConsole.WriteLine($"QUOTE_URL = {quote.Id}");Create a quote with a receive amount
Section titled “Create a quote with a receive amount”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.
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 dependenciesimport { createAuthenticatedClient } from '@interledger/open-payments'
// Initialize clientconst client = await createAuthenticatedClient({ walletAddressUrl: WALLET_ADDRESS, privateKey: PRIVATE_KEY_PATH, keyId: KEY_ID})
// Get wallet address informationconst walletAddress = await client.walletAddress.get({ url: WALLET_ADDRESS})
// Create quote with receive amountconst 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 } })
// Outputconsole.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
// Import dependenciesuse open_payments::client::api::AuthenticatedResources;use open_payments::client::utils::get_resource_server_url;use open_payments::snippets::utils::{create_authenticated_client, get_env_var, load_env};use open_payments::types::{resource::CreateQuoteRequest, Amount, PaymentMethodType, Receiver};
// Initialize clientlet client = create_authenticated_client()?;
// Create quote with receive amountlet access_token = get_env_var("QUOTE_ACCESS_TOKEN")?;let incoming_payment_url = get_env_var("INCOMING_PAYMENT_URL")?;let wallet_address_url = get_env_var("WALLET_ADDRESS_URL")?;let resource_server_url = get_resource_server_url(&wallet_address_url)?;
let request = CreateQuoteRequest::FixedReceiveAmountQuote { wallet_address: wallet_address_url, receiver: Receiver(incoming_payment_url), method: PaymentMethodType::Ilp, receive_amount: Amount { value: "1000".to_string(), asset_code: "EUR".to_string(), asset_scale: 2u8, },};
println!( "Quote create request JSON: {}", serde_json::to_string_pretty(&request)?);
let quote = client .quotes() .create(&resource_server_url, &request, Some(&access_token)) .await?;
// Outputprintln!("Created quote: {quote:#?}");// Import dependenciesuse OpenPayments\AuthClient;use OpenPayments\Config\Config;
// Initialize client$config = new Config( $WALLET_ADDRESS, $PRIVATE_KEY, $KEY_ID);$opClient = new AuthClient($config);
// Get wallet address information$wallet = $opClient->walletAddress()->get([ 'url' => $config->getWalletAddressUrl()]);
// 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", ], ]);
// Outputecho 'QUOTE_URL ' . $newQuote->id . PHP_EOL;echo 'QUOTE ' . print_r($newQuote, true) . PHP_EOL;package main
// Import dependenciesimport ( "context" "encoding/json" "fmt" "log"
op "github.com/interledger/open-payments-go" rs "github.com/interledger/open-payments-go/generated/resourceserver")
func main() { // Initialize client client, err := op.NewAuthenticatedClient(WALLET_ADDRESS_URL, PRIVATE_KEY_BASE_64, KEY_ID) if err != nil { log.Fatalf("Error creating authenticated client: %v\n", err) }
// Get wallet address information walletAddress, err := client.WalletAddress.Get(context.TODO(), op.WalletAddressGetParams{ URL: WALLET_ADDRESS_URL, }) if err != nil { log.Fatalf("Error fetching wallet address: %v\n", err) }
// Create quote with receive amount quote, err := client.Quote.Create(context.TODO(), op.QuoteCreateParams{ BaseURL: walletAddress.ResourceServer, AccessToken: QUOTE_ACCESS_TOKEN, Payload: rs.CreateQuoteJSONBody2{ WalletAddressSchema: WALLET_ADDRESS_URL, Receiver: INCOMING_PAYMENT_URL, Method: "ilp", ReceiveAmount: rs.Amount{ Value: "500", AssetCode: walletAddress.AssetCode, AssetScale: walletAddress.AssetScale, }, }, }) if err != nil { log.Fatalf("Error creating quote: %v\n", err) }
// Output quoteJSON, err := json.MarshalIndent(quote, "", " ") if err != nil { log.Fatalf("Error marshaling quote: %v\n", err) } fmt.Println("QUOTE:", string(quoteJSON)) fmt.Println("QUOTE_URL:", *quote.Id)}// Import dependenciesimport org.interledger.openpayments.httpclient.OpenPaymentsHttpClient;import org.interledger.openpayments.IOpenPaymentsClient;import org.interledger.openpayments.model.common.Amount;
// Initialize clientIOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet address informationvar receiverWallet = client.walletAddress().get("https://cloudninebank.example.com/merchant");var senderWallet = client.walletAddress().get("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = client.auth().grant().incomingPayment(receiverWallet);var incomingPayment = client.payment().createIncoming(receiverWallet, grantRequest, BigDecimal.valueOf(11.50));
// Create quote with receive amountvar quoteRequest = client.auth().grant().quote(senderWallet);var quote = client.quote().create(quoteRequest.getAccess().getToken(),senderWallet,incomingPayment,Optional.empty(),Optional.of(Amount.build(BigDecimal.valueOf(12.34), "USD"))// Receive Amount - Not the same as incoming payment amount.);
// Outputlog.info("QUOTE: {}", incomingPayment);// Import dependenciesusing Microsoft.Extensions.DependencyInjection;using OpenPayments.Sdk.Clients;using OpenPayments.Sdk.Extensions;using OpenPayments.Sdk.Generated.Resource;using OpenPayments.Sdk.HttpSignatureUtils;
// Initialize clientvar client = new ServiceCollection() .UseOpenPayments(opts => { opts.UseAuthenticatedClient = true; opts.KeyId = CLIENT_ID; opts.PrivateKey = KeyUtils.LoadPem(CLIENT_SECRET); opts.ClientUrl = new Uri(CLIENT_WALLET_ADDRESS); }) .BuildServiceProvider() .GetRequiredService<IAuthenticatedClient>();
// Get wallet address informationvar waInfo = await client.GetWalletAddressAsync(WALLET_ADDRESS);
// Create quote with receive amountvar quote = await client.CreateQuoteAsync( new AuthRequestArgs { Url = waInfo.ResourceServer, AccessToken = QUOTE_ACCESS_TOKEN, }, new QuoteBody { WalletAddress = waInfo.Id, Receiver = new Uri(INCOMING_PAYMENT_URL), Method = PaymentMethod.Ilp, ReceiveAmount = new Amount { Value = "500", AssetCode = waInfo.AssetCode, AssetScale = waInfo.AssetScale, } });
// OutputConsole.WriteLine($"QUOTE_URL = {quote.Id}");