Wormhole Integration
Solana Agent Kit provides comprehensive integration with Wormhole protocol for cross-chain operations, enabling token transfers, USDC transfers via Circle’s CCTP (Cross-Chain Transfer Protocol), and wrapped token creation across multiple blockchains.
Overview
The Wormhole integration enables:
- Transfer of tokens from Solana to other supported chains
- USDC transfers via Circle’s CCTP
- Creation of wrapped token versions on destination chains
- Querying supported chains and networks
Supported Chains
Wormhole supports multiple blockchains across different networks:
Mainnet:
- Solana
- Ethereum
- Avalanche
- Optimism
- Arbitrum
- Base
- Polygon
- Sui
- Aptos
Testnet:
- Solana
- Sepolia (Ethereum testnet)
- Avalanche testnet
- OptimismSepolia
- ArbitrumSepolia
- BaseSepolia
- Polygon testnet
Prerequisites
To use the Wormhole integration, you need to set up environment variables for the chains you plan to interact with:
# Solana configuration
SOLANA_PRIVATE_KEY=your_solana_private_key
# EVM configuration (Ethereum, Arbitrum, Optimism, etc.)
ETH_PRIVATE_KEY=your_ethereum_private_key
# Optional configurations for other chains
SUI_MNEMONIC=your_sui_mnemonic
APTOS_PRIVATE_KEY=your_aptos_private_key
Core Functions
Token Transfer
Transfer tokens from Solana to other supported chains:
import { SolanaAgentKit } from "solana-agent-kit";
const agent = new SolanaAgentKit(/* config */);
const result = await agent.methods.tokenTransfer({
destinationChain: "Ethereum",
network: "Mainnet",
transferAmount: "0.1",
tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" // USDC on Solana
});
Token Transfer Parameters
Parameter | Type | Description |
---|
destinationChain | string | Target blockchain (e.g., “Ethereum”, “Avalanche”) |
network | string | ”Mainnet”, “Testnet”, or “Devnet” |
transferAmount | string | Amount to transfer (in human-readable format) |
tokenAddress | string | Address of the token on Solana to transfer |
CCTP Transfer
Transfer USDC via Circle’s Cross-Chain Transfer Protocol:
const result = await agent.methods.cctpTransfer({
destinationChain: "Ethereum",
transferAmount: "10",
network: "Mainnet"
});
CCTP Transfer Parameters
Parameter | Type | Description |
---|
destinationChain | string | Target blockchain (e.g., “Ethereum”, “Base”) |
transferAmount | string | Amount of USDC to transfer |
network | string | ”Mainnet” or “Testnet” (default: “Mainnet”) |
Create Wrapped Token
Create a wrapped version of a Solana token on another chain:
const result = await agent.methods.createWrappedToken({
destinationChain: "Ethereum",
tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC on Solana
network: "Mainnet"
});
Wrapped Token Parameters
Parameter | Type | Description |
---|
destinationChain | string | Target blockchain for the wrapped token |
tokenAddress | string | Address of token on Solana to be wrapped |
network | string | ”Mainnet”, “Testnet”, or “Devnet” |
Get Supported Chains
Retrieve a list of chains supported by Wormhole:
const supportedChains = await agent.methods.getWormholeSupportedChains();
The integration provides LangChain tools for AI agent integration:
import { TokenTransferTool } from "solana-agent-kit";
const tokenTransferTool = new TokenTransferTool(agent);
// Tool input (JSON string):
const input = JSON.stringify({
destinationChain: "Ethereum",
network: "Mainnet",
transferAmount: "0.1",
tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
});
import { CctpTransferTool } from "solana-agent-kit";
const cctpTransferTool = new CctpTransferTool(agent);
// Tool input (JSON string):
const input = JSON.stringify({
destinationChain: "Ethereum",
transferAmount: "10",
network: "Mainnet"
});
import { CreateWrappedTokenTool } from "solana-agent-kit";
const createWrappedTokenTool = new CreateWrappedTokenTool(agent);
// Tool input (JSON string):
const input = JSON.stringify({
destinationChain: "Ethereum",
tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
network: "Mainnet"
});
import { GetWormholeSupportedChainsTool } from "solana-agent-kit";
const supportedChainsTool = new GetWormholeSupportedChainsTool(agent);
// No input required
Response Types
Token Transfer Response
interface TokenTransferResponse {
success: boolean;
status?: string;
sourceChain?: string;
destinationChain?: string;
amount?: string;
token?: string;
sourceTransaction?: string;
destinationTransaction?: string;
error?: string;
}
CCTP Transfer Response
interface CctpTransferResponse {
success: boolean;
status?: string;
sourceChain?: string;
destinationChain?: string;
amount?: string;
sourceTransaction?: string[];
attestation?: string[];
destinationTransaction?: string[];
automatic?: boolean;
error?: string;
}
Create Wrapped Token Response
interface CreateWrappedTokenResponse {
success: boolean;
wrappedToken?: {
chain: string;
address: string;
};
attestationTxid?: string;
error?: string;
}
Implementation Details
Token Transfer Process
- Initialize the Wormhole SDK with supported blockchain adapters
- Get chain contexts for source (Solana) and destination chains
- Create signers for both chains
- Determine token decimals and convert amount to base units
- Create and send token bridge transfer transaction
- Wait for attestation from Wormhole guardians
- Complete the transfer on the destination chain
CCTP Transfer Process
- Initialize the Wormhole SDK with supported blockchain adapters
- Get chain contexts for source (Solana) and destination chains
- Create signers for both chains
- Parse the transfer amount to correct decimal precision
- Create a USDC transfer object with specified parameters
- Initiate the transfer on the source chain
- Wait for the Circle attestation
- Complete the transfer on the destination chain
Wrapped Token Creation Process
- Check if the token is already wrapped on the destination chain
- If not wrapped, create an attestation on the source chain
- Wait for the attestation to be processed by Wormhole guardians
- Submit the attestation to the destination chain
- Poll for the wrapped token to be available
Error Handling
All functions include comprehensive error handling:
try {
const result = await agent.methods.tokenTransfer({
destinationChain: "Ethereum",
network: "Mainnet",
transferAmount: "0.1",
tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
});
if (!result.success) {
console.error("Transfer failed:", result.error);
// Handle error
}
} catch (error) {
console.error("Unexpected error:", error);
// Handle unexpected errors
}
Common Tokens
Common token addresses on Solana:
const TOKENS = {
USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
USDT: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
SOL: "So11111111111111111111111111111111111111112" // Wrapped SOL
};
Advanced Features
Manual vs Automatic Mode
For CCTP transfers, you can choose between manual and automatic mode:
// Manual mode (default)
const result = await agent.methods.cctpTransfer({
destinationChain: "Ethereum",
transferAmount: "10",
network: "Mainnet",
automatic: false // Manual mode
});
// Automatic mode with relayers
const resultAuto = await agent.methods.cctpTransfer({
destinationChain: "Ethereum",
transferAmount: "10",
network: "Mainnet",
automatic: true, // Automatic mode
nativeGasAmount: "0.01" // Gas for relayers
});
Checking If Token Is Already Wrapped
Before creating a wrapped token, you can check if it already exists:
import { isTokenWrapped } from "solana-agent-kit";
const wrapped = await isTokenWrapped(
wormholeInstance,
"Solana",
"Ethereum",
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
);
if (wrapped) {
console.log("Token is already wrapped:", wrapped);
} else {
// Create wrapped token
}
Utility Functions
Getting Token Decimals
import { getTokenDecimals } from "solana-agent-kit";
const decimals = await getTokenDecimals(
wormholeInstance,
tokenId,
sourceChain
);
Getting Signers
import { getSigner } from "solana-agent-kit";
const { chain, signer, address } = await getSigner(
chainContext,
gasLimit // Optional for EVM chains
);
Troubleshooting
Common Issues
- Missing Environment Variables: Ensure all required private keys are set
- Insufficient Funds: Make sure your wallet has enough tokens for the transfer
- VAA Not Found: Increase timeout for waiting for VAAs
- Transaction Failures: Check chain congestion and try again later
Debugging Tips
- Enable verbose logging for more detailed information
- Check transaction status on blockchain explorers
- Verify token addresses and chain identifiers
- Test on testnets before using mainnet
Resources
Responses are generated using AI and may contain mistakes.