Installation

npm install gasyard-sdk

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:
fromChain
string
required
Source chain name (e.g., “ethereum”, “arbitrum”, “base”)
toChain
string
required
Destination chain name
fromToken
string
required
Input token symbol or address
toToken
string
required
Output token symbol or address
amount
string
required
Amount in smallest unit (wei for ETH, 6 decimals for USDC)
recipient
string
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

NameChain ID
ethereum1
base8453
arbitrum42161
polygon137
optimism10
bnb56
sei1329
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>;
}