near-react-swap-widget
v1.0.0
Published
npm Package - @near-react/swap-widget
Readme
near-react-swap-widget
A React component for swapping tokens on the NEAR blockchain.
Installation
npm install near-react-swap-widget
Usage
import { NearReactSwapWidget } from 'near-react-swap-widget'
function App() {
return (
<NearReactSwapWidget
defaultFromToken="NEAR"
defaultToToken="USDC"
accountId="alice.near"
theme="light"
onSwap={(from, to, amount) => {
console.log(Swapping ${amount} ${from} → ${to})
}}
/>
)
}
Props
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| className | string | — | CSS class name for the widget container |
| style | React.CSSProperties | — | Inline styles for the widget container |
| defaultFromToken | string | "NEAR" | Token to swap from |
| defaultToToken | string | "USDC" | Token to swap to |
| accountId | string | — | NEAR account ID of the user |
| onSwap | (from: string, to: string, amount: string) => void | — | Callback fired when a swap is initiated |
| theme | 'light' \| 'dark' | — | Color theme of the widget |
Example with Dark Theme
<NearReactSwapWidget defaultFromToken="NEAR" defaultToToken="USDT" theme="dark" onSwap={(from, to, amount) => { console.log(from, to, amount) }} />
License
MIT
