The SDK separates what (the Velora methods) from how it talks to the chain and the API. You wire two things:
- A contract caller bridges between the SDK’s
transactCall / signTypedDataCall / staticCall interface and your wallet library.
- A fetcher bridges between the SDK’s
FetcherFunction and your HTTP client.
Simple SDK builds both for you from a single options object. Full SDK and Partial SDKs take them as constructor arguments.
Contract callers
viem
import { createWalletClient, custom } from "viem";
import { mainnet } from "viem/chains";
import { constructViemContractCaller } from "@velora-dex/sdk";
const walletClient = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum!),
});
const [account] = await walletClient.getAddresses();
const contractCaller = constructViemContractCaller(walletClient, account);
Write methods resolve to a viem Hex (the transaction hash).
For sending the result of sdk.swap.buildTx via viem, the SDK exports txParamsToViemTxParams to cast all string-numbers to BigInt:import { txParamsToViemTxParams } from "@velora-dex/sdk";
const tx = await sdk.swap.buildTx({
/* ... */
});
const viemTx = txParamsToViemTxParams(tx);
const hash = await walletClient.sendTransaction({ ...viemTx, account });
ethers v5
import { ethers } from "ethers";
import { constructEthersContractCaller } from "@velora-dex/sdk";
const contractCaller = constructEthersContractCaller(
{
ethersProviderOrSigner: signer, // JsonRpcProvider, Wallet, or Web3Provider
EthersContract: ethers.Contract,
},
account,
);
Write methods resolve to ethers.ContractTransaction. You can call .wait() directly on the result.
ethers v6
import { ethers } from "ethers";
import { constructEthersV6ContractCaller } from "@velora-dex/sdk";
const contractCaller = constructEthersV6ContractCaller(
{
ethersV6ProviderOrSigner: signer,
EthersV6Contract: ethers.Contract,
},
account,
);
Write methods resolve to ethers v6’s ContractTransactionResponse.
web3.js
import Web3 from "web3";
import { constructWeb3ContractCaller } from "@velora-dex/sdk";
const web3 = new Web3(Web3.givenProvider);
const contractCaller = constructWeb3ContractCaller(web3, account);
Write methods resolve to web3’s PromiEvent<TransactionReceipt>. Listen on transactionHash for early notification:
const eventfulTx = await sdk.swap.approveToken(amount, USDC);
eventfulTx.once("transactionHash", (hash: string) =>
console.log("tx sent:", hash),
);
Fetchers
axios
import axios from "axios";
import { constructAxiosFetcher } from "@velora-dex/sdk";
const fetcher = constructAxiosFetcher(axios);
fetch (Node 18+ and the browser)
import { constructFetchFetcher } from "@velora-dex/sdk";
const fetcher = constructFetchFetcher(fetch);
Custom fetcher
Any HTTP client works: implement FetcherFunction and pass it through. Useful for adding retries, logging, header injection, or wrapping an unusual transport.
import { constructSimpleSDK, type FetcherFunction } from "@velora-dex/sdk";
const customFetcher: FetcherFunction = async (options) => {
// requestParams may include AbortSignal; honor it for cancellation
const res = await myHttpClient(options.url, {
method: options.method,
headers: options.headers,
body: options.method === "POST" ? options.data : undefined,
signal: options.requestParams?.signal,
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.body;
};
const sdk = constructSimpleSDK({
chainId: 1,
fetcher: customFetcher,
});
For richer error semantics, throw a FetcherError and the SDK will re-throw it untouched so calling code can isFetcherError(err) and inspect the response.
wagmi recipe
If your app already uses wagmi, reuse the viem wallet client it manages:
import axios from "axios";
import { useConnection, useWalletClient } from "wagmi";
import {
constructPartialSDK,
constructAxiosFetcher,
constructViemContractCaller,
constructGetRate,
constructBuildTx,
constructApproveToken,
} from "@velora-dex/sdk";
const fetcher = constructAxiosFetcher(axios);
function useVeloraSDK() {
const { address } = useConnection();
const { data: walletClient } = useWalletClient();
if (!walletClient || !address) return null;
const contractCaller = constructViemContractCaller(walletClient, address);
return constructPartialSDK(
{
chainId: walletClient.chain.id,
fetcher,
contractCaller,
},
constructGetRate,
constructBuildTx,
constructApproveToken,
);
}
Memoize the result (with useMemo on the wallet client and address) to avoid rebuilding the SDK on every render.
Related pages
- Install covers peer dependencies for each wallet library.
- Simple SDK: uses these callers and fetchers via a single options object.
- Full SDK — takes the caller and fetcher you construct here.
- Partial SDK, same wiring, smallest bundle.
Last modified on June 14, 2026