SDK
Build a dapp
Last updated
Build a dapp
Last updated
The Defuse Protocol SDK is built on two core components that work together to provide a robust and flexible solution for cross-chain asset swaps:
Our swap logic is driven by two core state machines, implemented using XState:
Quote Machine: Handles the process of obtaining and managing swap quotes.
Swap Machine: Manages the entire swap process from initiation to completion.
These state machines are framework-agnostic and can be used on both client and server sides. They provide a clear and predictable flow for complex cross-chain swap operations, handling various states, transitions, and edge cases.
Key benefits of using state machines:
Clear visualization of the swap process
Easier management of complex logic and edge cases
Improved testability and maintainability
Framework-agnostic implementation
The Defuse SDK wraps the state machine logic and provides a complete solution as React components and hooks. This layer abstracts the complexity of state management and provides a user-friendly interface for developers to integrate swap functionality into their applications.
Key features of the Defuse SDK:
React Components: Ready-to-use components like SwapWidget
that encapsulate the entire swap interface.
Context Provider: SwapWidgetProvider
that manages the global state and provides necessary context to child components.
Hooks: Custom hooks that allow developers to interact with the swap logic programmatically.
Theming: Built-in theming support for easy customization.
This architecture allows for a separation of concerns, where the core swap logic is handled by the state machines, while the SDK provides an easy-to-use interface for React applications. Developers can leverage the power of state machines for complex logic handling while enjoying the simplicity of React components for UI integration.
Install the package:
Now that you’ve installed the SDK, you can use it in your application: