Skip to main content

Swap

To make it more convenient for users of various projects to manage their funds, Portkey provides the Swap SDK module for integration. Once it's integrated, users can seamlessly complete token swaps within the project without needing to exit, allowing them to quickly acquire the assets in need.

Swap homepage

Select the pair of tokens for swapping

Customise slippage

Confirm Swap

Swap homepage
Select the pair of tokens for swapping
Customise slippage
Confirm Swap

Installation

npm install @portkey/trader-react-ui@latest 
npm install @portkey/trader-core@latest

Usage

import { ComponentType, Swap, ISwapProps } from '@portkey/trader-react-ui';
import { AwakenSwapper, IPortkeySwapperAdapter, TTokenApproveHandler } from '@portkey/trader-core';

const App = () => {

const instance = new AwakenSwapper({
contractConfig: {
swapContractAddress: 'awakenSwapContractAddress',
rpcUrl: 'rpcUrl',
},
});

const tokenApprove: TTokenApproveHandler = () => {
// manager Approve action
}

const getOptions = async () => {
// some action
return {
contractOptions: {
// options
},
address: 'caAddress',
}
}

return
<Swap
selectTokenInSymbol={'ELF'}
selectTokenOutSymbol={'USDT'}
containerClassName='containerClassName'
componentUiType={ComponentType.Mobile}
onConfirmSwap={() => {
// after confirm action
}}
chainId={'tDVV'}
awaken={{
instance,
tokenApprove: isDiscover ? undefined : tokenApprove,
getOptions,
}}
/>
};

export default App;

API

PropertyDescriptionTypeDefaultVersion
containerClassNameClass name of the top level containerstring-0.0.1-alpha.17
componentUiTypeThe display of the component UIComponentTypeComponentType.web0.0.1-alpha.17
awakenThe data required for performing a swapIAwakenConfig-0.0.1-alpha.17
selectTokenInSymbolDefault token to be swapped fromstring-0.0.1-alpha.17
selectTokenOutSymbolDefault token to be swapped tostring-0.0.1-alpha.17
chainIdThe ID of the chain the user operates onChain-0.0.1-alpha.17
onConfirmSwapCallback when swap is successful()=>void;-0.0.1-alpha.17

IAwakenConfig

PropertyDescriptionTypeDefaultVersion
instanceAn instance of AwakenSwapper that is called when retrieving the tokenList and performing a swap.IPortkeySwapperAdapter-0.0.1-alpha.17
tokenApproveUsed during managerApprove. When logging in via SDK, this parameter is required.TTokenApproveHandler-0.0.1-alpha.17
getOptionsAsynchronous method which needs to return: Contract options required for the swap and caAddress() => Promise<{ contractOptions: TContractOption; address: string } | undefined | void>-0.0.1-alpha.17