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.
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 (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.
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.getWalletAddress("https://cloudninebank.example.com/merchant");var senderWallet = client.getWalletAddress("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = this.client.createGrantIncomingPayment(receiverWallet);var incomingPayment = this.client.createIncomingPayment(receiverWallet, grantRequest, BigDecimal.valueOf(11.25));
// Create quotevar quoteRequest = this.client.createGrantQuote(senderWallet);var quote = client.createQuote(quoteRequest.getAccess().getToken(), senderWallet, incomingPayment, Optional.empty(), Optional.empty());
// Outputlog.info("QUOTE: {}", incomingPayment);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 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.IOpenPaymentsClient;import org.interledger.openpayments.model.common.Amount;
// Initialize clientIOpenPaymentsClient client = OpenPaymentsHttpClient.defaultClient("WalletAddress","PrivateKeyPEM","KeyId");
// Get wallet address informationvar receiverWallet = client.getWalletAddress("https://cloudninebank.example.com/merchant");var senderWallet = client.getWalletAddress("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = this.client.createGrantIncomingPayment(receiverWallet);var incomingPayment = this.client.createIncomingPayment(receiverWallet, grantRequest, BigDecimal.valueOf(11.50));
// Create quote with debit amountvar quoteRequest = this.client.createGrantQuote(senderWallet);var quote = client.createQuote(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);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 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.getWalletAddress("https://cloudninebank.example.com/merchant");var senderWallet = client.getWalletAddress("https://cloudninebank.example.com/customer");
// Create incoming paymentvar grantRequest = this.client.createGrantIncomingPayment(receiverWallet);var incomingPayment = this.client.createIncomingPayment(receiverWallet, grantRequest, BigDecimal.valueOf(11.50));
// Create quote with receive amountvar quoteRequest = this.client.createGrantQuote(senderWallet);var quote = client.createQuote(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);