zksync-easy-onramp
v4.0.0
Published
SDK package for ZKsync easy on ramp
Readme
ZKsync Easy On-Ramp SDK
ZKsync Easy On-Ramp SDK simplifies fiat on-ramping for your application. This NPM package provides a seamless way to integrate fiat purchases and token swaps, ensuring a smooth user experience. It connects to a growing list of fiat on-ramp providers and leverages LI.FI for token swaps when needed. The SDK manages order tracking, transaction signing, and execution, delivering a complete end-to-end on-ramping solution.
Installation
npm install --save zksync-easy-onrampQuick start
Configure the SDK
import { createOnRampConfig } from "zksync-easy-onramp";
createOnRampConfig({
integrator: "ZKsync Easy OnRamp Demo",
dev: true, // add dev flag to test with sandboxes
});Request quotes
import { fetchQuotes } from "zksync-easy-onramp";
// fetching quotes for $25 USD for Ether on ZKsync
const quotes = await fetchQuotes({
toAddress: "0xE6a8bEEFC1Bca3046235e0d1f8db805734949024",
fiatAmount: 25,
fiatCurrency: "USD",
chainId: 324,
toToken: "0x000000000000000000000000000000000000800A",
});Execute a quote
import { executeRoute } from "zksync-easy-onramp";
const quotes = await fetchQuotes({...});
const selectedQuote = quotes[0];
// A quote needs to be converted to a route before executing.
const routeToExecute = quoteToRoute("buy", selectedQuote.paymentMethods[0], selectedQuote.provider);
const executedRoute = executeRoute(routeToExecute, {
onUpdateHook: (executingRoute) => {
// receive the latest state change
// of the quote that is executing
console.log(executingRoute);
}
});Further documentation
To read more about implementing and using the ZKsync Easy On-Ramp SDK, check out the section on ZKsync Docs.
Example
Check out the demo app to see a working implementation of the SDK in a Vue app.
License
This project is licensed under both the Apache-2.0 and MIT licenses.
