Library for integrating 1inch swap widget
.
See the live example here and the source code here.
Statements | Branches | Functions | Lines |
---|---|---|---|
npm install @1inch/embedded-widget
yarn add @1inch/embedded-widget
import {setup1inchWidget} from '@1inch/embedded-widget';
const iframeJsonRpcManager = setup1inchWidget({
chainId: 137,
sourceTokenSymbol: '1INCH',
destinationTokenSymbol: 'DAI',
hostElement: host,
provider: window.ethereum,
theme: 'light',
sourceTokenAmount: '15'
});
iframeJsonRpcManager.destroy() // Will remove iframe from the page and stop postMessage listening
iframeJsonRpcManager.onIframeLoad(() => { // Will call a callback when 1inch swap widget is fully loaded
console.log('1inch swap widget is loaded')
})
Option | Type | Example | Description |
---|---|---|---|
chainId | Number |
1 | 1inch supports several chains, see the actual list on 1inch.io |
sourceTokenSymbol | String |
USDT | Symbol of source token. See the full list of supported tokens on offical 1inch docs |
destinationTokenSymbol | String |
DAI | Symbol of destination token. See the full list of supported tokens on offical 1inch docs |
sourceTokenAmount | String |
200 | Optional. Using this option, you can pre-set the number of source tokens for the swap |
hostElement | HTMLElement |
document.body | The DOM element where the widget will be placed. You can change the witget size by changing size of the hostElement |
provider | EthereumProvider | window.ethereum | EIP-1193 provider for json-rpc requests to the wallet |
theme | light / dark |
light | Optional. Theme of 1inch widget UI. If not set, the widget will use the system theme |