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

dkosov-npm-repo-test

v1.0.7

Published

A small blazing fast wrapper over the VIA Router API for on-chain and cross-chain swaps. Our API allows you to find the best route for moving funds between chains!

Downloads

21

Readme

VIA SDK typescript

A small blazing fast wrapper over the VIA Router API for on-chain and cross-chain swaps. Our API allows you to find the best route for moving funds between chains!

Feature List

|feature|remark|method| |--|--|--| |get routes|Swaps/bridges cheapest routes|getRoutes| |check allowance|Allowance to check whether it's needed or not to approve|getAllowanceStatus| |build approval transaction|The transaction that approves the VIA contract to spend your token|buildApprovalTx| |build transaction|The transaction that will perform a swap/bridge according to the route|buildTx|

Installing

npm i @viaprotocol/router-sdk

Usage

First you need to initialize a VIA Client instance:

import Via from '@viaprotocol/router-sdk';

const DEFAULT_API_KEY = 'e3db93a3-ae1c-41e5-8229-b8c1ecef5583';
const cli = new Via({apiKey: DEFAULT_API_KEY, url: 'https://router-api.via.exchange', timeout: 30});

Get the best routes.

const fromChainId = 1;
const fromTokenAddress = '0x0000000000000000000000000000000000000000';
const fromAmount = Math.pow(10, 18);
const toChainId = 56;
const toTokenAddress = '0x0000000000000000000000000000000000000000';
const fromAddress = '0x856cc59aaE47997a1C8D5472Fc8dfef27821235d';  // might be null
const multiTx = false;  // whether to return routes with multiple user transactions

const routes = await cli.getRoutes(
    {
        fromChainId,
        fromTokenAddress,
        fromAmount,
        toChainId,
        toTokenAddress,
        fromAddress,
        multiTx
    }
);

Get allowance status You must approve the contract to spend your token. You can get route_id from the route you like received above in the code snippet.

const routeId = routes.routes[0];
const chainId = fromChainId;
const owner = "YOUR_WALLET_ADDRESS";
const tokenAddress = fromTokenAddress;
const numAction = 0;  // number of action in routes

const allowanceStatus = await cli.getAllowanceStatus(
    {owner, routeId, numAction}
);

Build approval transaction. Returns the transaction that approves the VIA API to spend your token.

const amount = fromAmount;

tx = await cli.buildApprovalTx(
    {routeId, owner, numAction}
)

Now you can build the transaction that will perform a crosschain swap according to the route.

# amount out minimal, you can get it from get_routes as to_token_amount
output = routes.routes[0].toTokenAmount

tx = await cli.buildTx(
    {
        routeId,
        fromAddress,
        receiveAddress,
        numAction
    }
)