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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@transitswap/js-sdk

v1.0.2

Published

Transit Swap js SDK

Downloads

5

Readme

transit-js-sdk

This SDK is a JavaScript library for buying or selling and cross swap on Transit Swap, so you don't need to interact with the Transit Swap API and smart contracts directly.

If you just want to get information about api params or return result, call the API directly.

Getting Started

The SDK without requires an Transit Swap API key.

Install

Install with

npm i @transitswap/js-sdk

Initiating SDK

const transit = require("@transitswap/js-sdk")

Constant Methods

  • Query all supported chains for Transit Swap. Return chain json array.
//chain json
//{
//  chain: 'ETH',
//  chainId: 1,
//  icon: 'https://tp-statics.tokenpocket.pro/token/tokenpocket-1654746200716.png'
//}

const chainList = await transit.swapV1.getSupportChain()
  • Query the smart contract address of the specified chain.
  • Before swap, the signer must approve ERC20 spending by the approveProxy contract
  • multiRouter is the router of aggregator swap. crossRouter is the router of cross chain swap.
const approveProxy = await transit.swapV1.getApproveProxy(chain)
const multiRouter = await transit.swapV1.getMultiRouter(chain)
const crossRouter = await transit.swapV1.getCrossRouter(chain)

Other Methods

  • Query Transaction details on Transit Swap
const hash = "0x0cec30133c4362c9053266e3bc67a5f2d25aac5d0a75a5a46e3cbc37a9a91573"
const res = await transitSwap.swapV1.quoteDetails(hash)
console.log("amount out:", res.getAmountOut())
  • To swap Native(0x0000000000000000000000000000000000000000) or Token, call the quoteSwap method:
const data = {
  chain: "BSC",
  token0: "0x0000000000000000000000000000000000000000",
  token1: "0x55d398326f99059ff775485246999027b3197955",
  decimal0: 18,
  decimal1: 18,
  to: "Your wallet address",
  amountIn: "1000000000000000000",
  impact: "300",
  amountOutMin: "0",
  part: 10,
  channel: "Your specified channel",
  issuer: "Your wallet address"
}
const res = await transitSwap.swapV1.quoteSwap(data)
if (res.isSuccess) {
  console.log("returun data:", res)
} else {
  console.log("query failure:", res.msg)
}
  • Query supported tokens & chains of cross, call the quoteCrossTokens method:
const res = await transitSwap.swapV1.quoteCrossTokens()
if (res.isSuccess) {
  console.log("returun data:", res.getBridgers(),res.getChains(),res.getTokens())
} else {
  console.log("query failure:", res.msg)
}
  • Before cross swap, should query the transfer limit amount, call the quoteCrossTransferLimit method:
const data = {
  token0: "0xa71edc38d189767582c38a3145b5873052c3e47a",
  token1: "0x55d398326f99059ff775485246999027b3197955",
  fromChainID: 128,
  toChainID: 56,
  bridge: "METAPATH"
}
const res = await transitSwap.swapV1.quoteCrossTransferLimit(data)
if (res.isSuccess) {
  console.log("returun data:", res.getMaximumSwap(),res.getMinimumSwap())
} else {
  console.log("query failure:", res.msg)
}

About channel

Transit Swap supports partner’s "channel merchants" who can set special channel rates and rebates. Welcome to be our partner!

Email: [email protected]

Twitter: https://twitter.com/TransitFinance

Telegram: https://t.me/Transit_Finance

Example: Cross swap USDT(BSC) to USDT(TRON) by METAPATH

If the bridge is METAPATH , should call the method CallbackSwap to speed up cross's transaction. You don't need to process the callback returned information.

const data = {
  bridge: "METAPATH",
  token0: "0x55d398326f99059ff775485246999027b3197955",
  token1: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
  decimal0: 18,
  decimal1: 6,
  to: "The recipient wallet",
  amountIn: "11000000",
  fromChainID: 56,
  toChainID: 95500,
  channel: "Your specified channel",
  issuer: "The signer wallet"
}
const res = await transitSwap.swapV1.quoteCrossSwap(data)
if(res.isSuccess) {
  //use res.getRouter(),res.getData() to send transaction... 
} else {
  console.log("query failure:",res.msg)
}

// optional
const callbackData = {
  bridge: "METAPATH",
  token0: "0x55d398326f99059ff775485246999027b3197955",
  token1: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
  decimal0: 18,
  decimal1: 6,
  to: "The recipient wallet",
  amountIn: "11000000",
  fromChainID: 56,
  toChainID: 95500,
  channel: "Your specified channel",
  issuer: "The signer wallet",
  amountOutMin: res.getAmountOut(),
  hash: ${hash}
}
if (res.getExchange()=="MetaPath") {
  await transitSwap.swapV1.CallbackSwap(callbackData)
}

Error Codes of API Response

This section is in the works and will provide more comprehensive documentation once completed.

The error information can now be fetched from 'msg'. If result='Failure' or isSuccess=false, it works.

Contributing

Transit Swap welcomes contributions in the form of GitHub issues and pull-requests.