Skip to content

maxatdeltafi/embedded-widget

 
 

Repository files navigation

1inch network

1inch embedded swap widget

Library for integrating 1inch swap widget.
See the live example here and the source code here.

Statements

Test coverage

Statements Branches Functions Lines
Statements Branches Functions Lines

Installation

Node

npm install @1inch/embedded-widget

Yarn

yarn add @1inch/embedded-widget

Usage

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')
})

Configuration

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 89.9%
  • JavaScript 10.1%