SDK Overview
The ZKsync Easy On-Ramp SDK package provides a seamless way to integrate fiat purchases and token swaps, ensuring a smooth and user-friendly experience. In its current state, the SDK supports ZKsync Era only—enabling a two-step flow where users on-ramp from fiat to ETH via Transak, then seamlessly swap ETH to any token using LI.FI. Once native interop is live, a third step will be added: transferring the purchased token directly to the user’s address on any destination chain within the Elastic Network. The SDK connects with a growing list of providers and aggregates quotes to ensure users receive the best available rates.
Installation
Install the ZKsync Easy On-Ramp SDK into your app.
npm install zksync-easy-onramp
You can view a demo example implementing the SDK into a Vue app.
Quick start
Configure the SDK
import { createOnRampConfig } from 'zksync-easy-onramp';
createOnRampConfig({
integrator: "ZKsync Easy OnRamp Demo",
provider: provider: EVM({...}) // Configure wallet provider for LiFI
},);
For additional configuration options, read more on Configure the SDK.
Request quotes
import { fetchQuotes } from 'zksync-easy-onramp';
const quotes = await fetchQuotes({
toAddress: "0xE6a8bEEFC1Bca3046235e0d1f8db805734949024",
fiatAmount: 50,
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);
}
});