Skip to main content

Quickstart

Get a swap running through Evix in under 5 minutes.

Prerequisites

  • A provisioned Evix deployment address for your chain
  • An RPC endpoint for the target chain
  • A wallet with token balances and approvals
info

Evix deployments are provisioned per customer, per chain. Contact Inductiv to get your deployment set up.

1. Install the SDK

npm install @inductiv/evix-sdk viem

2. Initialize the Client

import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { EvixClient } from "@inductiv/evix-sdk";

const account = privateKeyToAccount("0x...");

const publicClient = createPublicClient({
chain: base,
transport: http(),
});

const walletClient = createWalletClient({
account,
chain: base,
transport: http(),
});

const evix = new EvixClient({
chainId: base.id,
contractAddress: "0x...", // Your Evix deployment
publicClient,
walletClient,
});

3. Simulate a Swap

Always simulate before executing to get the expected output and compute your slippage tolerance.

const TOKEN_IN  = "0x..." as `0x${string}`; // e.g. USDC
const TOKEN_OUT = "0x..." as `0x${string}`; // e.g. WETH
const AMOUNT_IN = 1_000_000n; // 1 USDC (6 decimals)

const expectedOut = await evix.simulateSwap({
tokenIn: TOKEN_IN,
tokenOut: TOKEN_OUT,
amountIn: AMOUNT_IN,
deadline: BigInt(Math.floor(Date.now() / 1000) + 120),
minAmountOut: 0n, // No minimum for simulation
recipient: account.address,
});

console.log("Expected output:", expectedOut.toString());

4. Execute with Slippage Protection

const slippageBps = 50n; // 0.5%
const minOut = expectedOut - (expectedOut * slippageBps) / 10_000n;

const result = await evix.swap({
tokenIn: TOKEN_IN,
tokenOut: TOKEN_OUT,
amountIn: AMOUNT_IN,
deadline: BigInt(Math.floor(Date.now() / 1000) + 120),
minAmountOut: minOut,
recipient: account.address,
});

console.log("Swap executed:", {
amountOut: result.amountOut.toString(),
tx: result.transactionHash,
});
tip

For production use, keep deadlines tight (30–120 seconds) and always set a non-zero minAmountOut. See the Security guide for more best practices.

Next Steps