Socket
Socket
Sign inDemoInstall

@0x/0x-sdk

Package Overview
Dependencies
72
Maintainers
12
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @0x/0x-sdk

TypeScript SDK for building exchange functionality on Ethereum and EVM-compatible chains with the 0x API


Version published
Maintainers
12
Created

Readme

Source

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

npm install @0x/0x-sdk

# or

yarn add @0x/0x-sdk

Usage

Swap tokens with the 0x-sdk:

import { ZeroExSdk } from '@0x/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.

Keywords

FAQs

Last updated on 12 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc