Embeddable swap widget
Embed the Ophis swap app so users can trade from your site.
Install for React
-
Install the package. Add the widget and its React dependencies.
npm install @ophis/widget-react react react-dom -
Render the widget. Add
OphisWidgetto your page.import { OphisWidget } from '@ophis/widget-react';export function Swap() {return (<OphisWidgetparams={{ tradeType: 'swap', width: '450px', height: '640px' }}onReady={() => console.log('Ophis widget ready')}/>);} -
Connect a wallet. Pass an EIP-1193 injected wallet as
provider.
The wrapper supplies baseUrl and appCode automatically.
Install for JavaScript
-
Install the library. Use the underlying CoW Protocol widget library.
npm install @cowprotocol/widget-lib -
Create the widget. Add a container with the ID
ophis-widget, then point the widget at Ophis.import { createCowSwapWidget } from '@cowprotocol/widget-lib';const container = document.getElementById('ophis-widget')!;createCowSwapWidget(container, {params: {baseUrl: 'https://swap.ophis.fi', // the Ophis hostappCode: 'ophis',tradeType: 'swap',width: '450px',height: '640px',},});
Leave partnerFee unset to use Ophis's base and price-improvement fees. An explicit partnerFee uses that volume-fee bps value in place of the default policy.
Widget configuration
| Field | Default via @ophis/widget-react | Purpose |
|---|---|---|
baseUrl | https://swap.ophis.fi | Iframe host; override for a self-hosted or staging Ophis. |
appCode | ophis | Tags orders in appData. Set it to your registered code to see your volume in the earnings report. |
partnerFee | Unset | The iframe applies the complete Ophis fee policy. |
partnerFee.recipient | Ophis Safe when overridden | Pinned by the React wrapper. |
chainId, sell, buy, theme, tokenLists | Upstream defaults | CoW widget parameters pass through. |
Choose a theme
Set theme to 'light', 'dark' or a full palette object. The default uses Ophis app styling.
Run the demo
- Open the examples. Use examples/widget-embed/ for React, Next.js, vanilla JS and raw iframe snippets.
- Start the demo. Run
npx serve .in that folder and openindex.html.
Hosting and settlement
| Chains | Orderbook |
|---|---|
| Optimism, Unichain, Robinhood Chain, Arc | Ophis self-hosted orderbooks |
| Ethereum, Base, Arbitrum, Polygon, BNB, Gnosis, Avalanche, Linea, Plasma, Ink | api.cow.fi |
The widget selects the orderbook for the chosen chain. Use the standalone app for direct Circle bridging.
A self-hosted iframe host must allow third-party framing: set CSP frame-ancestors * and omit X-Frame-Options: SAMEORIGIN. The hosted app already allows framing. Users sign fund-moving actions in a wallet popup outside the iframe.
| License | Value |
|---|---|
| Widget | GPL-3.0 |