npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

swapbox-sdk

v1.0.82

Published

swapbox swapbox-sdk

Downloads

14

Readme

#swapbox-sdk对接文档 ###1.安装swapbox-sdk yarn add swapbox-sdk ###2.初始化swapbox-sdk

const swapboxSdk = require("swapbox-sdk");
swapboxSdk.mainnet(); // 主网调用
swapboxSdk.testNet(); // 测试网调用

###3.swapbox-sdk API

/**
* @description 获取swap预估手续费
* @param fromAsset {object} 源链资产(资产查询接口返回的资产信息)`
* @param toAsset {object} 目标链资产 
* @param fromAddress {object} 用户地址 EVM链传EVM地址, NULS链传NULS地址 
* @param inputType { 'src' | 'dest' } 当前用户输入的金额类型 
* @param amount {string} 用户需要兑换的金额 
* @param platform {string} 当前平台(传对接平台 SWFT | NABOX | 其他对接平台)
* @param toAddress {string} 用户接收地址(不填写默认为用户地址)
* @param type {string} 兑换类型普通跨链兑换传 1(BNB(BSC) => Polygon(USDT))其他兑换/跨链类型可不传
* @param slippage {string} 兑换类型普通跨链兑换传对应滑点(BNB(BSC) => Polygon(USDT))其他兑换/跨链类型可不传
* @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,
            nerveAssetId: '',
            nerveChainId: '',
        },
        {
            chain: 'Heco',
            chainId: '103',
            assetId: '0',
            contractAddress: '0xa8b8a0751b658dc8c69738283b9d4a79c87a3b3e',
            channelInfo: {
                'NERVE': {
                    pairAddress: 'TNVTdTSQoL9quSyGJCA9sY8pcMEVy4RN4EjbB'
                }
            },
            decimals: 18,
            nerveAssetId: '',
            nerveChainId: '',
        },
        '0x3083f7ed267dca41338de3401c4e054db2a1cd2f',
        'src',
        '100',
        'SWFT',
        '0x45cCF4B9F8447191C38F5134d8C58F874335028d',
        1,
        0.5
    );
// 返回值
feeInfo = {
    code: 1000, // 1000成功,其余都是失败  
    crossChainFee: '', // 跨链手续费(调用合约会用到)  
    originCrossChainFee: '',
    amountIn: '100', // 源链入金  
    amountOut: '99.98', // 用户收到目标链收到的金额  
    orderId: '', // 生成的订单id(调用合约会用到)  
    swapFee: '', // swap收取的手续(调用合约会用到)
    NULSContractGas: '',// NULS链交易会返回数据
    NULSContractTxData: {}, // NULS链交易会返回数据
    message: 'success'
}
/** 
 * * @description 发送稳定币交易(调用合约) 
 * * @param fromAddress {string} 当前用户地址 
 * * @param fromAsset {object} 源链资产(资产查询接口返回的资产信息) 
 * * @param toAsset {object} 目标链资产 
 * * @param amountIn {string} 源链入金(通过费率信息接口获取) 
 * * @param amountOut {string} 目标链入金(通过费率信息接口获取) 
 * * @param crossChainFee {string} 跨链手续费(通过费率信息接口获取) 
 * * @param orderId {string} 订单号(通过费率信息接口获取) 
 * * @param signAddress {string} 多签地址(通过后台config接口获取) 
 * * @param swapFee {string} 兑换收取的手续费(通过费率信息接口获取) 
 * * @param platform {string} 当前平台(传对接平台 SWFT | NABOX | 其他对接平台) 
 * * @param toAddress {string} 用户接收地址(不填写默认为用户地址)
 * * @param feeInfo {object} fee接口返回的数据 NULS链跨出交易必传
 * * @param signNULSAddress {string} NULS链跨出交易必传(当前NULS地址对应的EVM地址)
 * * @param network {string} NULS链跨出交易必传 主网(main) || 测试网(test)默认为 main
 * * @param walletType {string} NULS链跨出交易必传 当前连接的钱包类型(默认为 ethereum)
 * * @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,
        nerveAssetId: '',
        nerveChainId: '',
    }, 
    {
        chain: 'Heco',
        chainId: '103',
        assetId: '0',
        contractAddress: '0xa8b8a0751b658dc8c69738283b9d4a79c87a3b3e',
        channelInfo: {
            'NERVE': { pairAddress: 'TNVTdTSQoL9quSyGJCA9sY8pcMEVy4RN4EjbB' }
        },
        decimals: 18,
        nerveAssetId: '',
        nerveChainId: '',
    },
    feeInfo.amountIn,
    feeInfo.amountOut,
    feeInfo.crossChainFee.toString(),   
    feeInfo.orderId,
    '0xf85f03C3fAAC61ACF7B187513aeF10041029A1b2',
     feeInfo.swapFee.toString(),
     'NABOX',
     '0x45cCF4B9F8447191C38F5134d8C58F874335028d', 
     feeInfo,
     '0x45cCF4B9F8447191C38F5134d8C58F874335028d',
        'test'
    );
    // 返回值
    hashRes = {      
        code: 1000, // 1000成功,其余都是失败      
        hash: '', // 签名过后广播交易的hash      
        message: 'success'
   }
/** 
* @description 交易发出后记录一次hash 
* @param orderId {string}订单号 orderId 
* @param hash {string} 交易hash 
* @returns {Promise<void>} 
*/ 
const res = await swapboxSdk.recordHash(orderId, has);
// 返回值
res = {
    code: 1000,
    msg: '',
    data: {} // 当前订单信息
}