import { getClient, createClient } from "@relayprotocol/relay-sdk";
import { createWalletClient, createPublicClient, http } from "viem";
import { base } from "viem/chains";
// 1. Setup Wallet - Initialize your wallet using your preferred method
const account = {}; // Your wallet account (e.g., privateKeyToAccount, or injected wallet)
const wallet = createWalletClient({
account,
chain: base,
transport: http(),
});
const publicClient = createPublicClient({
chain: base,
transport: http(),
});
// 2. Initialize the Relay client
createClient({
baseApiUrl: "https://api.relay.link",
source: "YOUR_APP_NAME",
});
// 3. Get a quote using the SDK
const quote = await getClient().actions.getQuote({
chainId: 8453, // Base
toChainId: 42161, // Arbitrum
currency: "0x0000000000000000000000000000000000000000", // ETH
toCurrency: "0x0000000000000000000000000000000000000000", // ETH
amount: "100000000000000", // 0.0001 ETH
tradeType: "EXACT_INPUT",
wallet,
});
const requestId = quote.steps[0].requestId;
console.log(`Request ID: ${requestId}`);
// 4. Execute the quote and fast fill once the transaction is submitted
let txHash: string;
await getClient().actions.execute({
quote,
wallet,
onProgress: async ({ currentStep, currentStepItem, txHashes }) => {
// Once transaction is submitted, trigger fast fill immediately
if (txHashes && txHashes.length > 0 && !txHash) {
txHash = txHashes[0];
console.log(`Transaction submitted: ${txHash}`);
// 5. Call Fast Fill immediately after submitting (before waiting for confirmation)
const fastFillResult = await getClient().actions.fastFill({
requestId,
});
console.log("Fast fill initiated:", fastFillResult);
}
// Monitor progress
if (currentStep && currentStepItem) {
console.log(`Step: ${currentStep.action}, Status: ${currentStepItem.status}`);
}
},
});
console.log("Bridge completed successfully!");