LogoLogo
  • JuliaOS Documentation Hub
  • About JuliaOS
    • Mission & Vision
    • Features and Capabilities
    • Roadmap
    • Tokenomics
  • Ecosystem
    • Overview
  • Partners
    • Heurist
    • Fetch.ai
    • Soulgraph
    • cheqd.io
    • Aethir
    • Anyone
    • TensorLabs
    • Hashpower
  • Technology
    • Overview
    • Open Source
      • Modular Framework
      • CLI Mode
    • AI Platform
      • Dashboard
      • Agent Management
      • Swarm Management
      • Marketplace
      • Mining
    • LLM
    • Launchpad
    • Robotics & IOT
      • SwarmIOT
      • Modular AI with Robotics
        • J3OS MiniLLM
          • 🔧 Use Cases
  • Technical
    • Overview
    • Developer Hub
      • Getting Started
        • Installation Guide
          • Github Guide
        • Basic Concepts
        • Quick Start Guide
          • Handling secrets
        • Examples and Use
          • Example: Using the Trading Functionality
          • Example: Using the Benchmarking Feature
          • Example: Multi-Agent Swarm Coordination
          • Example: Using the Python Wrapper for LLM Integration
          • Example: Using Cross-Chain Bridges
          • Example: Creating and Running a Swarm Optimization
          • Page 4
      • Best Practices
        • Performance Tuning
        • Agent/Swarm Design Patterns
        • Best Practices & Patterns
        • Security Best Practices
      • CLI
        • JuliaOS CLI Interface
        • Agent Management (CLI)
        • CLI Configuration
        • Cross-Chain Hub (CLI)
        • Swarm Management (CLI)
        • CLI Troubleshooting
        • Wallet Management (CLI)
      • Framework SDK
        • Modules
          • Bridge
          • Agents Module
          • Dex
          • Swarms Module
          • Wallet
        • Python Wrapper
          • LangChain Integration
          • Python Wrapper
      • Contributing Guide
      • Extending JuliaOS
      • Development Setup & Conventions
      • Testing & Debugging
      • Troubleshooting
    • Architecture
      • High Level JuliaOS
      • CLI <-> Backend Communication
      • Data Storage Architecture
      • Framework Internals
      • Architecture Deep Dive
        • Architectual Notes
    • Concepts
      • Core Features & Concepts
      • Agents
        • Agent Skills & Specializations
      • Swarms
      • Neural Networks
      • Blockchains & Chains
      • Bridges (Cross-Chain)
      • Integrations
        • Google ADK
        • LLMs
        • Price Feed
        • DEX Integration
      • Storage
      • Trading Capabilities
      • Use Cases
      • Wallets
      • Portfolio Optimization
  • Research
    • JuliaOS Research
  • API Documentation
    • API Reference
      • API Reference: Julia Backend Commands
      • API Reference: CLI Commands
      • API Reference: Node.js API
      • API Reference: Python API
      • API Reference
  • Community
    • Community & Support
  • FAQ
    • General
    • Technical
    • Community
Powered by GitBook
On this page
Export as PDF
  1. Technical
  2. Developer Hub
  3. Getting Started
  4. Examples and Use

Example: Using Cross-Chain Bridges

Example: Using Cross-Chain Bridges

JuliaOS includes real implementations of multiple cross-chain bridge protocols (Wormhole, Axelar, LayerZero) for transferring assets between different blockchain networks. Here's how to use them:

# Using the CLI
./scripts/run-cli.sh  # or node packages/cli/interactive.cjs

# Select "🌉 Bridge Operations" from the menu
# Select "Bridge Tokens" from the submenu
# Choose a bridge protocol (Wormhole, Axelar, LayerZero)
# Follow the prompts to specify source chain, target chain, token, amount, and recipient
import asyncio
from juliaos import JuliaOS

async def bridge_tokens():
    # Initialize JuliaOS
    juliaos_client = JuliaOS(host="localhost", port=8052)
    await juliaos_client.connect()

    # Get supported bridges
    bridges = await juliaos_client.bridges.get_supported_bridges()
    print(f"Supported bridges: {bridges}")

    # Get supported chains for Wormhole
    chains = await juliaos_client.bridges.get_supported_chains("wormhole")
    print(f"Supported chains for Wormhole: {chains}")

    # Get supported tokens for a chain pair
    tokens = await juliaos_client.bridges.get_supported_tokens(
        bridge="wormhole",
        source_chain="ethereum",
        destination_chain="solana"
    )
    print(f"Supported tokens: {tokens}")

    # Estimate fee for a transfer
    fee = await juliaos_client.bridges.estimate_fee(
        bridge="wormhole",
        source_chain="ethereum",
        destination_chain="solana",
        token="USDC",
        amount="10.0"
    )
    print(f"Estimated fee: {fee}")

    # Create a wallet for the source chain
    wallet = await juliaos_client.wallets.create_wallet(
        name="Bridge Wallet",
        wallet_type="local",
        network="ethereum"
    )

    # Bridge tokens from Ethereum to Solana
    result = await juliaos_client.bridges.bridge_tokens(
        bridge="wormhole",
        source_chain="ethereum",
        destination_chain="solana",
        token="USDC",
        amount="10.0",
        recipient="9ywX...",  # Solana recipient address
        wallet_id=wallet["id"]
    )

    print(f"Bridge transaction initiated: {result['transaction_hash']}")

    # Check transaction status
    status = await juliaos_client.bridges.check_transaction_status(
        bridge="wormhole",
        source_chain="ethereum",
        transaction_hash=result["transaction_hash"]
    )

    print(f"Transaction status: {status['status']}")

    # Get transaction history
    history = await juliaos_client.bridges.get_transaction_history(
        wallet_id=wallet["id"],
        limit=10
    )

    print(f"Transaction history: {len(history['transactions'])} transactions found")

    await juliaos_client.disconnect()

# Run the bridge operation
asyncio.run(bridge_tokens())
# Using Julia directly
using JuliaOS.Bridge

# Get supported bridges
bridges = Bridge.get_supported_bridges()
println("Supported bridges: ", bridges)

# Get supported chains for Wormhole
chains = Bridge.get_supported_chains("wormhole")
println("Supported chains for Wormhole: ", chains)

# Create a wallet for the source chain
wallet = JuliaOS.Wallet.create_wallet(
    "Bridge Wallet",
    "local",
    "ethereum"
)

# Bridge tokens from Ethereum to Solana using Wormhole
result = Bridge.bridge_tokens(
    "wormhole",
    "ethereum",
    "solana",
    "USDC",
    "10.0",
    Dict(
        "recipient" => "9ywX...",  # Solana recipient address
        "wallet_id" => wallet["id"]
    )
)

# Check transaction status
status = Bridge.check_transaction_status(
    "wormhole",
    "ethereum",
    result["transaction_hash"]
)

println("Transaction status: ", status["status"])
PreviousExample: Using the Python Wrapper for LLM IntegrationNextExample: Creating and Running a Swarm Optimization

Last updated 1 month ago