///
The Quicksilver SDK's fluent Domain-Specific Language (DSL) transforms complex API interactions into elegant, type-safe, and expressive code. This example demonstrates how to create and manage various
32 views
~32 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
The Quicksilver SDK's fluent Domain-Specific Language (DSL) transforms complex API interactions into elegant, type-safe, and expressive code. This example demonstrates how to create and manage various transaction types—payments, scheduled transactions, and streaming payments—using the SDK's active models and fluent interface.
This page builds upon the concepts introduced in Getting Started. For a detailed look at the Transaction active model, refer to the API Reference: Transaction Model.
Here's the complete code from examples/2-fluent-transactions.ts illustrating the creation and management of different transaction types:
The demo showcases how to leverage the Account active model and its transaction() method to create various types of financial interactions. Each transaction returns a Transaction active model, allowing for direct interaction and management.
First, the QuicksilverClient is initialized, typically for the sandbox environment during development. Then, two Account models, sender and recipient, are created. Notice how client.accounts.create() directly returns an Account object, which is an "active model" that you can interact with directly.
A standard Payment transaction is the simplest form. You call the transaction() method directly on the sender Account instance, specifying the amount, currency, recipient (to), and transaction_type.
The paymentTx object returned is a Transaction active model. To finalize the payment, you call execute() on it. The SDK handles the API call and updates the paymentTx object's internal state. You can then check its state and getCost().
Scheduled transactions allow you to define a payment that will occur at a future date and time. This is achieved by setting transaction_type to 'Scheduled' and including a schedule timestamp within the meta object.
A scheduled transaction, once created, can also be canceled before its execution date using cancel() on the Transaction object.
Streaming transactions enable continuous, real-time payments based on a specified rate and unit (e.g., per second, per minute). The transaction_type is set to 'Stream', and the meta object specifies the rate and rate_unit.
Executing a streaming transaction initiates the stream. Over time, the accumulated cost will increase. You can refresh() the streamingTx object to get the latest data from the API, including the getCost() which reflects the total amount streamed so far.
This demo highlights the power of the Quicksilver SDK's fluent DSL and active models:
sender.transaction({...}).execute()).Account and Transaction objects are not just passive data structures but encapsulate behavior, allowing direct method calls for actions like delegate(), execute(), refresh(), and cancel().Payment, Scheduled, and Stream transactions with relevant metadata.This approach significantly simplifies the development of complex financial applications by providing an intuitive and powerful interface for programmable money.