Installation
Quick Start
import { Gasyard } from 'gasyard-sdk';
// Initialize client
const gasyard = new Gasyard({
apiKey: 'YOUR_API_KEY'
});
// Get a quote
const quote = await gasyard.getQuote({
fromChain: 'ethereum',
toChain: 'arbitrum',
fromToken: 'ETH',
toToken: 'USDC',
amount: '1000000000000000000' // 1 ETH in wei
});
// Execute the swap
const tx = await gasyard.execute(quote, {
signer: yourSigner
});
Core Methods
getQuote
Get a quote for a cross-chain swap:
Source chain name (e.g., “ethereum”, “arbitrum”, “base”)
Input token symbol or address
Output token symbol or address
Amount in smallest unit (wei for ETH, 6 decimals for USDC)
Optional: different recipient address
const quote = await gasyard.getQuote({
fromChain: 'ethereum',
toChain: 'arbitrum',
fromToken: 'ETH',
toToken: 'USDC',
amount: '1000000000000000000',
recipient: '0x...' // optional
});
Response:
{
"quoteId": "quote_abc123",
"fromChain": "ethereum",
"toChain": "arbitrum",
"fromToken": "ETH",
"toToken": "USDC",
"amountIn": "1000000000000000000",
"amountOut": "2500000000",
"minAmountOut": "2475000000",
"fee": "7500000",
"expiresAt": 1735689600
}
execute
Execute a quoted swap:
const tx = await gasyard.execute(quote, {
signer: yourSigner,
onProgress: (status) => {
console.log(status);
// 'pending' | 'submitted' | 'bridging' | 'completed'
}
});
getStatus
Check the status of an order:
const status = await gasyard.getStatus(orderId);
Response:
{
"orderId": "order_xyz789",
"status": "completed",
"fromTxHash": "0xabc...",
"toTxHash": "0xdef...",
"amountReceived": "2480000000"
}
getSupportedTokens
Get tokens supported on a chain:
const tokens = await gasyard.getSupportedTokens('ethereum');
getConfig
Get full network configuration:
const config = await gasyard.getConfig();
Chain Names
| Name | Chain ID |
|---|
ethereum | 1 |
base | 8453 |
arbitrum | 42161 |
polygon | 137 |
optimism | 10 |
bnb | 56 |
sei | 1329 |
movement | — |
solana | — |
Error Handling
import { GasyardError } from 'gasyard-sdk';
try {
const quote = await gasyard.getQuote({ ... });
const tx = await gasyard.execute(quote);
} catch (error) {
if (error instanceof GasyardError) {
switch (error.code) {
case 'INSUFFICIENT_LIQUIDITY':
// Handle liquidity error
break;
case 'QUOTE_EXPIRED':
// Refresh quote
break;
case 'INVALID_PARAMETER':
// Check parameters
break;
}
}
}
TypeScript Types
import type {
Quote,
QuoteParams,
ExecuteOptions,
TransactionStatus,
NetworkConfig
} from 'gasyard-sdk';
Framework Examples
import { useState } from 'react';
import { Gasyard } from 'gasyard-sdk';
import { useWalletClient } from 'wagmi';
const gasyard = new Gasyard({ apiKey: process.env.GASYARD_API_KEY });
function BridgeButton() {
const [status, setStatus] = useState('idle');
const { data: walletClient } = useWalletClient();
const handleBridge = async () => {
setStatus('quoting');
const quote = await gasyard.getQuote({
fromChain: 'ethereum',
toChain: 'arbitrum',
fromToken: 'ETH',
toToken: 'USDC',
amount: '1000000000000000000'
});
setStatus('executing');
await gasyard.execute(quote, {
signer: walletClient,
onProgress: setStatus
});
};
return <button onClick={handleBridge}>{status}</button>;
}
import { Gasyard } from 'gasyard-sdk';
import { ethers } from 'ethers';
const gasyard = new Gasyard({ apiKey: process.env.GASYARD_API_KEY });
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
async function bridge() {
const quote = await gasyard.getQuote({
fromChain: 'ethereum',
toChain: 'base',
fromToken: 'USDC',
toToken: 'USDC',
amount: '1000000000' // 1000 USDC
});
const tx = await gasyard.execute(quote, { signer: wallet });
console.log('Transaction:', tx.hash);
// Poll for completion
let status;
do {
await new Promise(r => setTimeout(r, 5000));
status = await gasyard.getStatus(tx.orderId);
} while (status.status !== 'completed');
console.log('Complete:', status.toTxHash);
}
Links