Widget
Implement the Synapse Bridge into your dApp frontend
The Synapse Widget is a trivial implementation of the current Synapse bridge that enables protocols to integrate the bridge into their Frontend with little to no Engineering resources.
This explains how to integrate the bridge widget into your dApp in just a few minutes. This widget enables users to bridge tokens directly on your site, utilizing the Synapse Protocol. Example use cases include:
Building a custom frontend for the Synapse Protocol
Bridging assets in a DeFi application
Acquiring a token to participate in a web3 game
This guide shows how to customize the widget to seamlessly blend with your app's theme by altering colors, fonts, and the token list. Learn to make the widget appear as an integral part of your application.
Implementation
The widget is available on npm or yarn.
npm:
yarn:
Get Started
To get started, import the Widget
React component into your App. You will need a web3Provider
parameter to pass to the widget. The demo landing page app, for example, defines this provider from the ethers
library. However, the component supports any similar provider:
Your site should now display a fully operational bridge widget integrating the routes and tokens supported by the Synapse protocol. By utilizing Synapse's multiple routers, you will be able to find the best quotes to support your bridging use case.
Bridge Widget Props
The widget accepts a number of props to customize its functionality and appearance. Below is a quick summary with more detailed explanations later on.
web3Provider
Web3Provider. Required.
customRpcs
Custom JSON-RPC endpoints for your consumer application. Optional but recommended.
customTheme
Custom theme for the widget. Optional. If not provided, defaults to light theme.
container
HTML element to render the widget in. Optional. If not provided, false.
targetChainIds
List of chain IDs for the destination side of your consumer app. Optional. If not provided, defaults to all Synapse Protocol supported networks.
targetTokens
List of tokens to display in the widget. These tokens are imported from the widget package. Optional. If not provided, defaults to all Synapse Protocol supported tokens.
protocolName
A short name for users of the widget to identify the protocol. Optional. If not provided, defaults to 'Target'.
hideConsoleErrors
Boolean to enable suppressing Synapse (SDK, Widget) console.error messages in your consumer app's browser. If not provided, defaults to logging error messages.
A list of
targetTokens
can be found hereA list of Synapse Protocol supported chains can be found here
web3Provider prop (required)
ethers v6
ethers v5
Enhanced and Reliable Performance
The bridge widget is a React component designed for straightforward integration into any React-based project. Engineered for immediate functionality, and apart from a web3Provider
, it requires no initial parameters or web3 setup to begin operation. The widget facilitates bridging across all networks where the Synapse Protocol is active.
While the widget is primed for immediate use without configuration as it provides some basic primary and fallback JSON-RPC endpoints, we encourage developers to specify their own for enhanced performance. This can be done by including a customRpcs
parameter in the format of an object with chain ids as keys and their associated RPC endpoints as values.
Token and Chain Customization
To further tailor the bridge widget to meet the specific demands of your project, additional optional targetTokens
and targetChainIds
parameters are provided. These allow for customizing which chain and tokens your consuming application will support bridging to. This is effectively a way to filter for specific tokens on destination chain your application's users bridge.
Note: Token naming convention is based on the tokens provided by @synapsecns/widget
. For example, USDC on Metis is METISUSDC
instead of simply USDC
. The package's src/constants/bridgeable.ts
file contains a detailed list of supported tokens and the chains they live on. Additionally, to see a detailed list of Synapse Protocol supported chains, please see src/constants/chains.ts
.
useBridgeSelections Hook
The widget also provides a useBridgeSelections
hook that can be used to access the selected tokens and chains. This hook returns an object of type BridgeSelections
which has fields of originChain
, originToken
, destinationChain
, and destinationToken
.
originChain
and destinationChain
structure:
originToken
and destinationToken
structure:
In the consumer app:
Theme Customization
The widget is designed to be easily customized to match your app's theme. The widget accepts an optional customTheme
configurable bgColor
parameter for 'dark'
, 'light'
, and custom color modes:
Additionally, the widget supports more complex custom themes with the customTheme
property. This allows for more fine-grained control over the widget's colors and fonts.
Please see the examples/landing-page
folder for more examples.
Container Customization
The widget additionally supports a container
property of true
or false
to adjust its width to the container it's in.
Example Apps
Within the repository's /examples
folder, there are three example apps. The landing-page
folder contains a fully functional demo with customizations of the widget. The with-react
and with-next
folders contain a simple implementation of the widget using React and Next.js, respectively.
If you have any questions or need help implementing the widget, feel free to reach out to the team in Discord!
Last updated