DeFi Components
Uniswap V3 swap quotes and transaction building with Zafeguard DeFi components.
DeFi Components
Zafeguard includes native Uniswap V3 integration for token swaps — get a live quote, then build and broadcast the swap transaction.
Public RPC URLs enforce rate limits per IP address and can fail under concurrent load. Use a private endpoint (Alchemy, Infura, QuickNode, or self-hosted). See Connecting to any chain.
GET_UNISWAP_SWAP_QUOTE
GET_UNISWAP_SWAP_QUOTE DeFi Workflow Component
Fetch a live swap quote from Uniswap. Returns the best output amount across the configured protocol versions.
Config
| Field | Type | Default | Description |
|---|---|---|---|
version | 'v2' | 'v3' | 'v4' | 'all' | 'all' | Uniswap version(s) to query. 'all' returns the best quote across all supported versions |
Inputs
| Field | Type | Description |
|---|---|---|
jsonRpcUrl | string | JSON-RPC endpoint for the target chain |
tokenIn | string | Input token contract address |
tokenOut | string | Output token contract address |
amountIn | string | Input token amount in smallest unit (bigint string, e.g. "1000000000000000000" for 1 ETH) |
Outputs
| Field | Type | Description |
|---|---|---|
amountOut | string | Best estimated output amount (bigint string) |
totalFee | number | Total pool fee in basis points (e.g. 30 = 0.3%) |
gasEstimate | string | Estimated gas cost for the swap (bigint string) |
SDK example
import { WorkspaceClient, ComponentModule } from '@zafeguard/caller-sdk';
const workspace = new WorkspaceClient({ apiKey: process.env.ZAFEGUARD_API_KEY! });
const quote = await workspace.call(ComponentModule.GET_UNISWAP_SWAP_QUOTE, {
jsonRpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/KEY',
chainId: 1,
tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
amountIn: '1000000000000000000', // 1 ETH in wei
}).promise();
console.log(quote.amountOut); // "1850000000" (1,850 USDC)
console.log(quote.totalFee); // 30 (0.3%)BUILD_EVM_UNISWAP_SWAP_CALLDATA
BUILD_EVM_UNISWAP_SWAP_CALLDATA DeFi Workflow Component
Build the encoded calldata for a Uniswap swap. Pipe the output into BUILD_EVM_TRANSACTION to produce an unsigned transaction ready for signing and broadcast.
Config
None.
Inputs
| Field | Type | Description |
|---|---|---|
jsonRpcUrl | string | JSON-RPC endpoint |
chainId | number | Chain ID |
tokenIn | string | Input token address |
tokenOut | string | Output token address |
recipient | string | Address to receive the output tokens |
amountIn | number | Exact input amount |
amountOutMinimum | number? | Minimum output (slippage protection). Defaults to 0 — always set this in production |
Outputs
| Field | Type | Description |
|---|---|---|
unsignedTransaction | string | Unsigned swap transaction |
SDK example
const swapTx = await workspace.call(ComponentModule.BUILD_EVM_UNISWAP_SWAP_CALLDATA, {
jsonRpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/KEY',
chainId: 1,
tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
recipient: '0xMyWalletAddress',
amountIn: 1_000_000_000_000_000_000,
amountOutMinimum: 1_840_000_000, // min 1,840 USDC (1% slippage)
}).promise();Complete swap workflow
STRING_CONSTANT (RPC URL)
│
├──▶ GET_EVM_CHAIN_ID
│ │
│ └──▶ GET_UNISWAP_SWAP_QUOTE
│ │ amountOut
│ ▼
│ (compute amountOutMinimum with slippage)
│
└──▶ BUILD_EVM_UNISWAP_SWAP_CALLDATA
│ unsignedTransaction
▼
SIGN_WITH_KEY_SHARE ──▶ SIGN_EVM_TRANSACTION
│
▼
BROADCAST_EVM_TRANSACTION
│
▼
WAIT_FOR_EVM_TRANSACTION
Always set amountOutMinimum based on the quoted amountOut minus your acceptable slippage (e.g. 0.5–1%). Setting it to 0 exposes the transaction to sandwich attacks.
Gnosis Safe
Zafeguard Gnosis Safe components — deploy multisigs, build and sign Safe transactions, manage owners, and batch calls with multicall.
EVM Cross-Chain Bridges
Bridge tokens across EVM chains in a single source-chain transaction. Fully decentralized — no API key, on-chain quotes only, auto-routed to the cheapest path.