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

@routerprotocol/asset-transfer-sdk-ts

v0.4.0-beta-2

Published

Provides functions to use pathfinder api, through which one can use Router's asset transfer solution.

Downloads

10

Readme

asset transfer sdk

Provides functions to use pathfinder api, through which one can use Router's asset transfer solution.

PathFinder SDK

To simplify the process of carrying out cross-chain swaps using Router Nitro, we have abstracted the process of interacting with Nitro's bridge contracts using our Asset Transfer SDK. Follow this documentation to integrate and use Nitro's Asset Transfer SDK.

Instalation

Install Nitro's Asset Transfer SDK into your JavaScript development environment by running the following command in your terminal:

npm install @routerprotocol/asset-transfer-sdk-ts

Initializing

After installing the module, import and initialize it into your code:

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";

const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);

You can use Network.Testnet for mandara and Network.Mainet for mainnet.

Example:

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";

const YOUR_WIDGET_ID = 24 // get your unique sdk id by contacting us on Telegram
const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);

Performing a Cross Chain Transaction

1️⃣ Request a Quote

To initiate a cross-chain transaction, you first need to obtain a quote from the Pathfinder API. The quote requires the following information:

  • sourceChainId: The ID of the source blockchain.
  • sourceTokenAddress: The address of the token on the source blockchain.
  • destinationChainId: The ID of the destination blockchain.
  • destinationTokenAddress: The address of the token on the destination blockchain.
  • expandedInputAmount: The amount of the token you want to transfer, in its smallest unit (like wei for ETH).

Use the getQuote method of the Pathfinder instance to request a quote:

const quote = await pathfinder.getQuote({
            sourceChainId,
            sourceTokenAddress,
            destinationChainId,
            destinationTokenAddress,
            expandedInputAmount,
        });

The getQuote method returns an object containing:

  • Fee details
  • Estimated amount to be received
  • Estimated time of completion

and more fields. Here's a example:

Getting a quote for transferring 10 USDT from Fuji to Mumbai:

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";

// initialize a Pathfinder instance
const YOUR_WIDGET_ID = 24 // get your unique sdk id by contacting us on Telegram
const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);

const main = async() => {


// getting a quote for 10 USDT from Fuji to Mumbai
const quote = await pathfinder.getQuote({
            sourceChainId: "43113",
            sourceTokenAddress: "0xb452b513552aa0B57c4b1C9372eFEa78024e5936",
            destinationChainId: "80001",
            destinationTokenAddress: "0x22bAA8b6cdd31a0C5D1035d6e72043f4Ce6aF054",
            expandedInputAmount: "10000000",
        });

console.log(quote)
}

main()

The Response

2️⃣ Executing a Quote

After getting quote for executing the quote you need have EvmSigner for evm chains, NearAccount for near and tronweb for Tron. You can create them using private keys rpc using the following functions or you can pass your own.

        import { evmSignerFromPrivateKeyAndRpc } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/EvmChainClient';
        import { getTronWeb } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/TronChainClient';
        import { nearSignerFromPrivateKey } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/NearChainClient';

        const evmSigner = evmSignerFromPrivateKeyAndRpc(evmPrivateKey, EVM_RPC);
        const tronSigner = getTronWeb(tronPrivateKey, TRON_RPC);
        const nearSigner = await nearSignerFromPrivateKey(nearAccountId, nearPrivateKey, nearAccount);

Complete implemenation of executing the quote.

TRON

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";
import { evmSignerFromPrivateKeyAndRpc } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/EvmChainClient';
        import { getTronWeb } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/TronChainClient';

// initialize a Pathfinder instance
const YOUR_WIDGET_ID = 24 // get your unique sdk id by contacting us on Telegram
const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);
const TRON_RPC="https://api.shasta.trongrid.io"
const main = async() => {

    // building evmsigner
            const evmSigner = evmSignerFromPrivateKeyAndRpc(evmPrivateKey, TRON_RPC);
    // building tron signer
                    const tronSigner = getTronWeb(tronPrivateKey, TRON_RPC);

// getting a quote for 10 USDT from Tron to Mumbai
const quote = await pathfinder.getQuote({
            sourceChainId: "2494104990", // tron chainId
            sourceTokenAddress: "0xF2340B8D37A198B2D66795C8B5B7C467CF92C4EC", // tron token address
            destinationChainId: "80001",
            destinationTokenAddress: "0x22bAA8b6cdd31a0C5D1035d6e72043f4Ce6aF054",
            expandedInputAmount: "1000000",
        });
        const transaction = await pathfinder.executeQuote({
            quote,
            slippageTolerance: "1",
            senderAddress: evmSigner.address, // tron address
            receiverAddress: evmSigner.address,
        },
            {
                evmSigner,
                tronweb: tronSigner
            }
        );

main()

EVM

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";
import { evmSignerFromPrivateKeyAndRpc } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/EvmChainClient';

// initialize a Pathfinder instance
const YOUR_WIDGET_ID = 24 // get your unique sdk id by contacting us on Telegram
const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);

const main = async() => {

    // building evmsigner
            const evmSigner = evmSignerFromPrivateKeyAndRpc(evmPrivateKey, "https://rpc.ankr.com/avalanche_fuji");


// getting a quote for 10 USDT from Fuji to Mumbai
const quote = await pathfinder.getQuote({
            sourceChainId: "43113",
            sourceTokenAddress: "0xb452b513552aa0B57c4b1C9372eFEa78024e5936",
            destinationChainId: "80001",
            destinationTokenAddress: "0x22bAA8b6cdd31a0C5D1035d6e72043f4Ce6aF054",
            expandedInputAmount: "10000000",
        });

        // execute quote handles approval as well
         const transaction = await pathfinder.executeQuote({
            quote,
            slippageTolerance: "1",
            senderAddress: evmSigner.address,
            receiverAddress: evmSigner.address,
        },
            {
                evmSigner
            }
        );

}

main()

NEAR

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";
import { nearSignerFromPrivateKey } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/NearChainClient';

// initialize a Pathfinder instance
const YOUR_WIDGET_ID = 24 // get your unique sdk id by contacting us on Telegram
const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);

const main = async() => {

    // building near account
        const nearRpc = "https://rpc.testnet.near.org"
        const nearSigner = await nearSignerFromPrivateKey(nearAccountId, nearPrivateKey, "testnet", nearRpc);


// getting a quote for 10 USDT from Fuji to Mumbai
 const quote = await pathfinder.getQuote({
            sourceChainId: "near-testnet", // cross check 
            sourceTokenAddress: "usdt_router.router_protocol.testnet", // near usdt address
            destinationChainId: "80001",
            destinationTokenAddress: "0x22bAA8b6cdd31a0C5D1035d6e72043f4Ce6aF054",
            expandedInputAmount: "1000000000000000000",
        });
        const transaction = await pathfinder.executeQuote({
            quote,
            slippageTolerance: "1",
            senderAddress: "joydeeeep.testnet",
            receiverAddress: "0x40d5250D1ce81fdD1F0E0FB4F471E57AA0c1FaD3",
        },
            {
                nearAccount: nearSigner
            }
        );

}

main()

3️⃣ Getting transaction status

To get transaction status you need to pass the source transaction hash to the following function.

const status = await pathfinder.getTransactionStatus(SRC_TXN_HASH);

Example:

import { Pathfinder, Network } from "@routerprotocol/asset-transfer-sdk-ts";
import { evmSignerFromPrivateKeyAndRpc } from '@routerprotocol/asset-transfer-sdk-ts/pathfinder/ChainClient/EvmChainClient';

// initialize a Pathfinder instance
const YOUR_WIDGET_ID = 24 // get your unique sdk id by contacting us on Telegram
const pathfinder = new Pathfinder(Network.Testnet, YOUR_WIDGET_ID);

const main = async() => {

    // building evmsigner
            const evmSigner = evmSignerFromPrivateKeyAndRpc(evmPrivateKey, "https://rpc.ankr.com/avalanche_fuji");


// getting a quote for 10 USDT from Fuji to Mumbai
const quote = await pathfinder.getQuote({
            sourceChainId: "43113",
            sourceTokenAddress: "0xb452b513552aa0B57c4b1C9372eFEa78024e5936",
            destinationChainId: "80001",
            destinationTokenAddress: "0x22bAA8b6cdd31a0C5D1035d6e72043f4Ce6aF054",
            expandedInputAmount: "10000000",
        });

        // execute quote handles approval as well
         const transaction = await pathfinder.executeQuote({
            quote,
            slippageTolerance: "1",
            senderAddress: evmSigner.address,
            receiverAddress: evmSigner.address,
        },
            {
                evmSigner
            }
        );

        const status = await pathfinder.getTransactionStatus(transaction);

}

main()

AssetGuard SDK (E2E automation test suite)

Exposes a class called AssetGuard though which you can tests muliple transactions in bulk.