Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
johnrjj-0x-sdk
Advanced tools
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.
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.
Follow this instruction to create a PAT with access to read:packages.
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/
npm install @0xproject/0x-sdk
# or
yarn add @0xproject/0x-sdk
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();
This repository includes a basic example in the [/examples](/examples)
folder which demonstrates basic exchange functionality. Follow these instructions to run the example:
/example
foldercd /example
yarn
yarn dev
Please follow this project's contributing guidelines.
FAQs
nothing
The npm package johnrjj-0x-sdk receives a total of 4 weekly downloads. As such, johnrjj-0x-sdk popularity was classified as not popular.
We found that johnrjj-0x-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.