Skip to content
✈️ TokenFlight SDK

ethers

This example uses the built-in @tokenflight/adapter-ethers package.

Live project Open in StackBlitz

StackBlitz tip: run pnpm --filter @tokenflight/swap build and pnpm --filter @tokenflight/adapter-ethers build once before pnpm dev.

Terminal window
pnpm add @tokenflight/swap @tokenflight/adapter-ethers ethers
import { useEffect, useMemo } from 'react';
import { TokenFlightSwap } from '@tokenflight/swap';
import { EthersWalletAdapter } from '@tokenflight/adapter-ethers';
export default function App() {
const walletAdapter = useMemo(() => {
if (typeof window === 'undefined' || !window.ethereum) return null;
return new EthersWalletAdapter(window.ethereum);
}, []);
useEffect(() => {
if (!walletAdapter) return;
const swap = new TokenFlightSwap({
container: '#swap-widget',
config: { theme: 'light' },
walletAdapter,
});
swap.initialize();
return () => swap.destroy();
}, [walletAdapter]);
return <div id="swap-widget" style={{ minHeight: 560 }} />;
}