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

quontral

v1.0.26

Published

Dex API endpoints and Token Swap library for Web3 applications

Downloads

29

Readme


Features:

  • Dex API endpoints for Web3 transactions
  • Web3 wallet configurations/authentications (login/sign)
  • Token allowances for web3 wallets and sending transactions
  • Handling big numbers and floating points
  • utility functions to help you build your dex

... and much more. Check the official Quontral docs for more details.

🚀 Quick start

If you're new to Quontral, check the quickstart guide in the official docs on how to get started.

1. Install Quontral

The easiest way to integrate the Quontral SDK into your JavaScript project is through the npm module.

Install the package via npm:

npm install quontral

Adding Quontral to the frontend project is by the following

import Quontral from 'quontral';

2. Initialize Quontral

After your dependency is added, you simply need to initialize quontral with class initialization:

⚠️ Warning: Make sure to keep your api key private

const service = new Quontral({ apiKey: 'YOUR_API_KEY' });

3. Using Dex API endpoints

After that we can use service functions to interact with the Dex API and Web3 wallet.

// ...

const priceResponse = await service.getPrice({
  buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
  sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
  sellTokenAmount: '1000000000000000000',
});

const quoteResponse = await service.getQuote({
  buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
  sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
  sellTokenAmount: '1000000000000000000',
});

4. Using services and utils

There are some utility functions which can help you build your dex even more quicker,

// ...

// This will initialize and configure the current Web3 wallet.
service.utils.connectWallet({ chainId: 56 });

// This will create an allowance based on your params on your web3 wallet for the desired token.
service.setAllowance({
  ownerAddress: '0x123', // your web3 wallet address
  sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1', // token address to create allowance for
});

5. Sending transaction using api data

// ...

const { data } = await service.getQuote({
  buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
  sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
  sellTokenAmount: '1000000000000000000',
});

// Send the transaction request on the current web3 wallet provider with the given api data of quontral
const receipt = await service.sendTransaction(data);

Or you can use the web3 library itself

import Web3 from 'web3';

// Initialize new web3 instance with the given provider
const web3 = new Web3(Web3.givenProvider);

// Our endpoint data for the transaction
const { data } = await service.getQuote({
  buyTokenAddress: '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56',
  sellTokenAddress: '0x3019bf2a2ef8040c242c9a4c5c4bd4c81678b2a1',
  sellTokenAmount: '1000000000000000000',
});

// Finally do the transaction on current wallet
const receipt = await web3.eth.sendTransaction(res.data);

6. Signin current Web3 wallet

// ...

// You can use these data pieces to save the users wallet credentials when signed
const { message, signature } = await service.sign({ address: '0x66E5869be1309a543A752aA24CfA251E86234fcc', domain: 'quontral.com', uri: 'https://app.quontral.com' });