SwapBox V1 SDK
Install swapbox-sdk
yarn add swapbox-sdk
Initialize swapbox-sdk
const swapboxSdk = require("swapbox-sdk");
swapboxSdk.mainnet(); // Mainnet call
swapboxSdk.testNet(); // testnet callSwapbox-sdk API
/**
* @description Get the estimated swap fee
* @param fromAsset {object} Source chain assets (asset information returned by the asset query interface)`
* @param toAsset {object} target chain asset
* @param fromAddress {object} user address
* @param inputType { 'src' | 'dest' } The type of amount entered by the current user
* @param amount {string} The amount the user needs to redeem
* @param platform {string} The current platform (pass the docking platform SWFT | NABOX | other docking platforms)
* @returns {Promise<{orderId: *, crossChainFee: *, amountIn: (*|BigNumber), amountOut: (*|BigNumber)}|{code, message: (string|*)}>}
*/
const feeInfo = await swapboxSdk.getSwapEstimateFeeInfo(
{
chain: 'BSC',
chainId: '102',
assetId: '0',
contractAddress: '0xd0a347e0ebea8f8efc26d539e17853c8e7a721c4',
channelInfo: {
'NERVE': { pairAddress: 'TNVTdTSQoL9quSyGJCA9sY8pcMEVy4RN4EjbB' }
},
decimals: 18
},
{
chain: 'Heco',
chainId: '103',
assetId: '0',
contractAddress: '0xa8b8a0751b658dc8c69738283b9d4a79c87a3b3e',
channelInfo: {
'NERVE': {
pairAddress: 'TNVTdTSQoL9quSyGJCA9sY8pcMEVy4RN4EjbB'
}
},
decimals: 18
},
'0x3083f7ed267dca41338de3401c4e054db2a1cd2f',
'src',
'100',
'SWFT'
);
// return value
feeInfo = {
code: '1000', // 1000 is successful, the rest are failures
crossChainFee: '', // cross-chain fee (used to call the contract)
amountIn: '100', // source chain deposit
amountOut: '99.98', // The user receives the amount received by the target chain
orderId: '', // The generated order id (used by the calling contract)
swapFee: '', // The procedure for swap collection (will be used to call the contract)
message: 'success'
}Last updated