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

johnrjj-0x-sdk

v0.0.3

Published

nothing

Downloads

3

Readme

0x-sdk

0x SDK is a TypeScript SDK for building exchange functionality on Ethereum and EVM-compatible chains. 0x SDK uses 0x API to aggregate liquidity. Building exchange functionality with the 0x API requires integrators to go through a number of steps. Integrators may need to manage chain IDs, API endpoints, convert numbers, approve tokens, sign messages, communicate with smart contracts, etc. The 0x SDK aims to simplify these steps.

Installation

As this sdk is published to Github Packages as a private package, instead of a public package in npm registry, users will need to create a credential (PAT in this case) and config npm before installing it.

Create a Github Personal access token (PAT)

Follow this instruction to create a PAT with access to read:packages.

Update your .npmrc

Add the following lines to your $HOME/.npmrc file (create it if not exists). Replace YOUR_PAT with your PAT generated in the first step.

//npm.pkg.github.com/:_authToken=YOUR_PAT
@0xproject:registry=https://npm.pkg.github.com/

Install package

npm install @0xproject/0x-sdk

# or

yarn add @0xproject/0x-sdk

Usage

Swap tokens with the 0x-sdk:

import { ZeroExSdk } from '@0xproject/0x-sdk';

// Instantiate SDK
const sdk = new ZeroExSdk();
const takerAddress = await signer.getAddress();

// Request params for the `/swap` resource to swap 1 WETH for DAI
const params = {
  sellToken: WETH_ADDRESS,
  buyToken: DAI_ADDRESS,
  sellAmount: '100000000000000000',
  takerAddress,
};

// Get price to swap 1 WETH for DAI
const price = await sdk.getIndicativePrice({
  resource: 'swap',
  params,
  chainId,
});

// Get firm quote to swap 1 WETH for DAI
const quote = await sdk.getFirmQuote({
  resource: 'swap',
  params,
  chainId,
});

// Approve ZeroEx Exchange Proxy to spend WETH
const contractTx = await sdk.approveToken({
  tokenContractAddress: WETH_ADDRESS,
  contractAddressToApprove: ZEROEX_CONTRACT_ADDRESS,
  signer,
});

await contractTx.wait();

// Submit the quote to ZeroEx Exchange Proxy
const txResponse = await sdk.fillOrder({ quote, signer, chainId });

// Wait for the transaction to be mined
const { transactionHash } = await txResponse.wait();

Example

This repository includes a basic example in the [/examples](/examples) folder which demonstrates basic exchange functionality. Follow these instructions to run the example:

  1. Navigate to the /example folder
cd /example
  1. Install the dependencies
yarn
  1. Run the example app
yarn dev

Contributing

Please follow this project's contributing guidelines.