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 call

Swapbox-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'
}
/**
 * * @description Send stablecoin transaction (call contract)
 * * @param fromAddress {string} current user address
 * * @param fromAsset {object} Source chain assets (asset information returned by the asset query interface)
 * * @param toAsset {object} target chain asset
 * * @param amountIn {string} Source chain deposit (obtained through the rate information interface)
 * * @param amountOut {string} Target chain deposit (obtained through the rate information interface)
 * * @param crossChainFee {string} Cross-chain fee (obtained through the rate information interface)
 * * @param orderId {string} Order number (obtained through the rate information interface)
 * * @param signAddress {string} Multi-signature address (obtained through the background config interface)
 * * @param swapFee {string} The fee charged for exchange (obtained through the rate information interface)
 * * @param platform {string} The current platform (pass the docking platform SWFT | NABOX | other docking platforms)
 * * @returns {Promise<{message: string, code: number}|{code: number, hash: *}|{msg: (*|string), code: (number|string|number)}>}
 * */

const hashRes = swapboxSdk.sendStableSwapTransaction(
    '0x3083f7ed267dca41338de3401c4e054db2a1cd2f',
    {
        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
    },
    feeInfo.amountIn,
    feeInfo.amountOut,
    feeInfo.crossChainFee.toString(),
    feeInfo.orderId,
    '0xf85f03C3fAAC61ACF7B187513aeF10041029A1b2',
     feeInfo.swapFee.toString()
    );
    // return value
    hashRes = {
        code: '1000', // 1000 is successful, the rest are failures
        hash: '', // hash of broadcast transaction after signing
        message: 'success'
   }
/**
* @description record a hash after the transaction is sent
* @param orderId {string} order number orderId
* @param hash {string} transaction hash
* @returns {Promise<void>}
*/
const res = await swapboxSdk.recordHash(orderId, has);
// return value
res = {
    code: 1000,
    msg: '',
    data: {} // current order information
}

Last updated