Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
LABS
Guides

How to Experiment With Cross-Chain Composability

A practical guide for developers to build and test cross-chain applications using major interoperability protocols. Includes code snippets for token bridging and contract messaging.
Chainscore © 2026
introduction
HANDS-ON TUTORIAL

How to Experiment With Cross-Chain Composability

A practical guide to building applications that combine smart contracts and assets across multiple blockchains using bridges and message-passing protocols.

Cross-chain composability refers to the ability of decentralized applications (dApps) to interact with and leverage assets, data, and logic from multiple, distinct blockchains. This moves beyond simple asset transfers to enable complex, multi-chain applications. For example, a yield aggregator on Arbitrum could source liquidity from Ethereum mainnet, execute a trade on a Polygon DEX, and deposit the resulting tokens into a lending protocol on Base. This interconnected functionality is powered by a combination of cross-chain messaging protocols like LayerZero, Axelar, and Wormhole, and bridges that facilitate asset transfers.

To start experimenting, you first need to understand the core architectural patterns. The dominant model is the arbitrary message passing bridge, which allows you to send arbitrary data (not just tokens) between chains. This data can be function calls, state updates, or NFT metadata. Key protocols provide developer SDKs: LayerZero offers the Endpoint interface, Axelar provides the AxelarGateway contract and JavaScript SDK, and Wormhole has the Core Bridge contract and Wormhole SDK. Your dApp's smart contract on the source chain calls into one of these protocols to send a cross-chain message, which is then verified and delivered to a destination contract you control.

A basic experiment involves creating a simple cross-chain counter. Deploy identical smart contracts on two testnets (like Sepolia and Mumbai). The contract should have a function to increment its counter and send a message via your chosen protocol to instruct the counterpart contract on the other chain to also increment. Here's a simplified snippet for a hypothetical sendMessage call:

solidity
// In your source chain contract
function incrementAndSend(uint16 targetChainId, bytes32 targetAddress) external payable {
    localCounter++;
    bytes memory payload = abi.encode("increment");
    ICrossChainMessenger(messengerAddress).sendMessage{value: msg.value}(
        targetChainId,
        targetAddress,
        payload
    );
}

The destination contract would have a receiveMessage function, callable only by the protocol's verified relayer, to decode the payload and increment its own counter.

When designing composable applications, you must account for asynchronous execution and error handling. A cross-chain transaction is not atomic; it involves separate transactions on the source and destination chains, with a variable delay in between. Your contracts need to manage pending states and implement retry logic or fallbacks for failed messages. Furthermore, security is paramount: always validate the message sender on the destination chain to ensure it is the official protocol relayer, and be mindful of gas costs on the destination chain, which often need to be estimated and provided by the user or your application logic on the source side.

For advanced experimentation, explore generalized cross-chain applications. Use the Chainlink CCIP for finance-grade messaging with execution guarantees, or Hyperlane's modular security stack to customize your verification model. Tools like SocketDL provide a unified API to access multiple liquidity bridges, enabling you to build the best-rate cross-chain swaps. Start by forking existing open-source examples from the Axelar Examples repository or LayerZero's Omnichain contracts, then modify them to implement your own multi-chain logic, such as cross-chain governance or NFT minting on a different chain.

prerequisites
EXPERIMENTAL GUIDE

Prerequisites and Setup

This guide outlines the essential tools and foundational knowledge required to build and test cross-chain applications.

Before writing any code, you need a solid development environment. Start by installing Node.js (v18 or later) and a package manager like npm or yarn. You'll also need a code editor such as VS Code. For blockchain interaction, install the Foundry toolkit for smart contract development and testing, and Hardhat for its robust plugin ecosystem. Finally, set up a wallet like MetaMask and fund it with testnet ETH on networks like Sepolia or Goerli. This setup provides the core toolchain for building, deploying, and interacting with smart contracts across chains.

Understanding the core concepts is critical. You should be familiar with EVM-compatible blockchains (like Ethereum, Polygon, Arbitrum) and their fundamental differences in gas costs and finality. Grasp how message passing protocols work; these are the mechanisms that allow one chain to trustfully read or trigger actions on another. Key protocols include LayerZero for arbitrary messaging, Axelar for generalized cross-chain calls, and Wormhole for token bridging and data. Knowing the trade-offs between these—security models, latency, and cost—is essential for choosing the right tool.

For experimentation, you'll need access to testnets and faucets. Most major Layer 2s and alternative chains have public testnets. Acquire test tokens from faucets for: Sepolia ETH, Polygon Mumbai MATIC, Arbitrum Sepolia ETH, and Avalanche Fuji AVAX. Services like the Chainlink Faucet provide multiple tokens. You will use these to deploy contracts and pay for gas on different chains during your tests. Keeping a spreadsheet of your deployed contract addresses per chain will help you manage your experiments.

Your first practical step is to initialize a project. Create a new directory and run npm init -y. Then, install essential dependencies: npm install ethers hardhat @nomicfoundation/hardhat-toolbox. Initialize a Hardhat project with npx hardhat init and select the TypeScript template for better type safety. This creates a basic project structure with contracts/, scripts/, and test/ folders. Configure your hardhat.config.ts file with the RPC URLs and private keys for your chosen testnets to enable multi-chain deployment.

With the project ready, write a simple cross-chain counter as a starter experiment. Deploy identical Counter contracts on two testnets (e.g., Sepolia and Mumbai). Then, use a cross-chain messaging protocol's SDK, like Axelar's, to send a increment() call from one chain to the other. This involves: funding the transaction on the source chain, specifying the destination chain and contract address, and paying for gas on the destination chain. This minimal example teaches you the core workflow of composing actions across separate state machines.

Finally, prioritize security in your experiments. Always use environment variables (with a .env file and the dotenv package) to manage private keys and API secrets. Test exhaustively on testnets before considering mainnet. Use tools like Slither or Mythril for static analysis of your smart contracts. Remember, cross-chain apps introduce new attack vectors—like relayers failing or destination chain reverts—so your error handling and transaction status checking must be robust. Start simple, understand each step, and gradually increase complexity.

key-concepts-text
PRACTICAL GUIDE

How to Experiment With Cross-Chain Composability

Cross-chain composability enables applications to interact across blockchains. This guide explains the core concepts and provides a practical framework for developers to build and test interoperable dApps.

Cross-chain composability is the ability for decentralized applications (dApps) and smart contracts on one blockchain to seamlessly interact with and utilize assets, data, or logic from another blockchain. Unlike traditional DeFi legos confined to a single chain, this expands the design space exponentially. It allows developers to combine the unique strengths of different networks—such as Ethereum's security for settlement, Arbitrum's low-cost execution, and Polygon's user base—into a single, unified application flow. The goal is to create a user experience where the underlying blockchain is abstracted away.

To experiment effectively, you must understand the foundational messaging protocols that enable this communication. LayerZero and Axelar are prominent general message passing protocols. They use a system of on-chain endpoints, off-chain relayers, and oracle networks to validate and deliver messages between chains. Wormhole employs a guardian network for attestation, while Chainlink's CCIP integrates oracle and cross-chain capabilities. For your experiments, start by reviewing the documentation for one of these protocols to understand its security model, supported networks, and fee structure.

A practical first project is building a cross-chain governance dashboard. Here's a conceptual flow using a Hyperlane-like framework: Your dApp on Ethereum mainnet needs to query voting power from stakers on Avalanche. 1. Your Ethereum contract calls the local Mailbox outbox. 2. An interchain security module validates the message. 3. A relayer network delivers it to the Avalanche Mailbox inbox. 4. A contract on Avalanche reads the staking contract, then initiates a return message with the data. You can test this using testnets like Sepolia and Fuji before deploying on mainnet.

When designing composable logic, consider asynchronous execution and error states. A call from Chain A to Chain B does not get an immediate return value; it triggers a separate callback function later. Your contracts must handle this delay and implement logic for failed messages, which may require state reconciliation or manual recovery functions. Tools like SocketDL and LI.FI offer SDKs that abstract some complexity, providing unified APIs for liquidity bridging and generic message passing, which is excellent for prototyping user-facing features quickly.

For advanced experimentation, explore arbitrary message bridging to trigger complex logic. Instead of just moving assets, you could have a user's action on Optimism autonomously mint an NFT on Base, stake it on Polygon, and stream rewards back to Arbitrum—all in a single transaction. This requires careful gas management across chains and robust error handling. Start by forking existing open-source examples from the Axelar GMP Examples repository or LayerZero's Omnichain contracts to study the patterns for sending, receiving, and verifying interchain transactions.

The final step is rigorous testing. Use local forked environments with tools like Foundry and Hardhat to simulate multiple chains. Services like Connext's nxtp and Axelar's local development setup provide sandboxes to deploy mock bridges and test message flows end-to-end without spending gas. Prioritize security audits for any mainnet deployment, as cross-chain contracts increase the attack surface. By methodically building from simple data queries to complex multi-chain workflows, you can effectively harness the power of cross-chain composability.

MESSAGE PASSING

Cross-Chain Protocol Comparison

A comparison of leading protocols for building cross-chain applications, focusing on developer experience and security models.

Feature / MetricLayerZeroWormholeAxelarCCIP

Architecture

Ultra Light Node (ULN)

Guardian Network

Proof-of-Stake Validators

Decentralized Oracle Network

Security Model

Executor + Oracle

19/20 Guardian Consensus

Proof-of-Stake w/ Slashing

Risk Management Network

Gas Abstraction

Programmability

Omnichain Fungible Tokens (OFT)

Token Bridge & NFTs

General Message Passing (GMP)

Arbitrary Messaging

Avg. Finality Time (Mainnet)

< 1 min

~15 sec

~6 min

~3-5 min

Developer SDK

@layerzerolabs/lz-sdk

@wormhole-foundation/sdk

@axelar-network/axelarjs-sdk

@chainlink/ccip-sdk

Native Gas Token Support

Approx. Gas Cost per Tx

$2-10

$5-15

$1-5

$10-25

layerzero-implementation
IMPLEMENTING CROSS-CHAIN WITH LAYERZERO

How to Experiment With Cross-Chain Composability

This guide explains how to build and test applications that combine logic and assets across multiple blockchains using the LayerZero messaging protocol.

Cross-chain composability enables smart contracts on different blockchains to interact seamlessly, creating unified applications. Unlike traditional bridges that only move assets, composability allows for complex logic execution across chains. For example, a user could supply collateral on Ethereum to mint a stablecoin on Avalanche, all within a single transaction flow. The LayerZero protocol facilitates this by providing a lightweight, trust-minimized messaging layer that connects over 50 blockchains, including Ethereum, Arbitrum, Polygon, and BNB Chain. Its core components are the Endpoint, Oracle, and Relayer, which work together to verify and deliver messages.

To start experimenting, you need to understand the two primary contract types in a LayerZero application: the Endpoint and your Omnichain Contract. The Endpoint (ILayerZeroEndpoint) is the on-chain entry point deployed on each supported chain; your application sends and receives messages through it. Your Omnichain Contract is your custom application logic that implements the ILayerZeroReceiver interface. The key function is lzReceive(), which is called by the Endpoint when a cross-chain message arrives. You must also handle the _nonce and _srcChainId parameters to ensure message order and verify the source chain.

A basic implementation involves sending a message from Chain A to Chain B. On the source chain, your contract calls endpoint.send{value: fee}(), specifying the destination chain ID, target contract address, payload data, and payment parameters. The payload is arbitrary bytes you define, such as a function selector and encoded arguments. You must also pay a small native token fee to cover the Oracle and Relayer services. On the destination chain, the Endpoint validates the message proof via the Oracle (block header) and Relayer (transaction proof) before calling your contract's lzReceive() function with the payload.

For development and testing, use the LayerZero Testnet. Deploy your contracts to testnets like Sepolia, Arbitrum Sepolia, and Polygon Amoy. Configure your contract with the correct testnet Endpoint addresses, which are documented in the LayerZero docs. Use the LayerZero Scan to monitor message status and debug delivery issues. A common testing pattern is to send a simple "ping" message that triggers a "pong" response back to the source chain, verifying the round-trip communication. Always estimate gas properly using estimateFees() before sending to avoid failed transactions.

Advanced composability patterns include cross-chain debt positions, where liquidation logic on one chain is triggered by price updates from another, and omnichain NFTs that can change state or metadata based on actions taken on any connected chain. Security is critical: always validate the _srcAddress in lzReceive() to prevent spoofing, use nonces to guard against replay attacks, and consider implementing a pause mechanism for your contract's cross-chain functions. For production, audit your payload encoding/decoding logic thoroughly, as this is a common source of vulnerabilities.

axelar-implementation
BUILDING WITH AXELAR GENERAL MESSAGE PASSING

How to Experiment With Cross-Chain Composability

A practical guide to building applications that interact with multiple blockchains using Axelar's General Message Passing (GMP).

Axelar's General Message Passing (GMP) is a protocol that enables smart contracts on one blockchain to call functions on contracts deployed on another. This is the foundation for cross-chain composability, allowing developers to build applications that leverage the unique features and liquidity of multiple networks. Unlike simple token bridges, GMP enables arbitrary data and value transfer, unlocking complex logic like cross-chain lending, governance, and NFT minting. You can start experimenting with GMP using Axelar's testnet, which supports chains like Ethereum's Sepolia, Avalanche Fuji, and Polygon Mumbai.

To begin, you'll need to understand the core components. The Axelar Gateway contract on each chain acts as the entry and exit point for messages. Your source-chain application calls callContract on its local Gateway, specifying the destination chain and contract address. The Axelar network's validators observe this request, reach consensus, and relay the payload to the destination Gateway, which finally executes the call. For developers, the AxelarJS SDK and AxelarGMPRecoveryAPI simplify interaction, handling gas estimation, transaction status tracking, and error recovery.

A common starting experiment is a simple cross-chain counter. Deploy a smart contract on two testnets (e.g., Avalanche Fuji and Polygon Mumbai) that implements the IAxelarExecutable interface. This interface requires an _execute function, which is the callback that the destination Gateway will invoke. Your source contract uses the SDK to send a GMP payload instructing the destination contract to increment its counter. This demonstrates the full flow: sending a payload, having it attested by the Axelar network, and executing logic on the remote chain.

For more advanced experimentation, consider cross-chain token transfers with logic. Instead of just bridging USDC, send it with a message that automatically deposits it into a lending protocol on the destination chain. This requires paying for gas on the destination chain in the native token, which Axelar can handle via gas services. You can estimate costs using the SDK's estimateGasFee function. Always implement comprehensive error handling, using the GMP Recovery API to query transaction status and manually execute calls if automatic execution fails.

Testing and security are critical. Use Axelar's testnet and local development tools like the Axelar Local Dev environment to simulate cross-chain calls without spending gas. Audit your _execute function for reentrancy and validate all incoming data, as the payload originates from an external system. Review Axelar's documentation on security best practices before moving to mainnet. This approach allows you to build truly interconnected applications that are not limited by the boundaries of a single blockchain.

wormhole-implementation
TUTORIAL

Sending Messages with Wormhole

A practical guide to using Wormhole's generic messaging protocol to enable communication and composability between smart contracts on different blockchains.

Wormhole's Generic Message Passing (GMP) protocol is the foundation for its cross-chain applications. Unlike simple token bridges, GMP allows arbitrary data—any encoded bytes—to be sent from a smart contract on a source chain to a smart contract on a destination chain. This data could represent a governance vote, a swap instruction, an NFT mint command, or any other contract call. The protocol handles the secure attestation and relay of this data, enabling truly composable, multi-chain applications. You can explore the core contracts on GitHub.

To send a message, your source chain contract calls the wormhole core contract's publishMessage function with your arbitrary payload and a consistency level (e.g., 200 for instant finality on EVM chains). This emits a LogMessagePublished event containing a unique sequence number. Off-chain, Wormhole's Guardian network observes this event, forms a Signed VAA (Verified Action Approval), which is a cryptographically signed attestation of your message. This VAA is then made available for relay to the destination chain.

On the destination chain, a relayer service must submit the signed VAA to the Wormhole core contract's parseAndVerifyVM function. If the signatures are valid, the contract decodes the VAA, confirming the message's origin chain, sender address, and your original payload. Your destination contract, typically via the Wormhole Relayer SDK or a custom integration, then receives and processes this verified payload. This two-step process—publish on source, verify and execute on destination—ensures trust-minimized cross-chain state changes.

A common pattern is to use the Wormhole Relayer SDK, which bundles the VAA relay with the destination contract call into a single paid transaction. For example, after publishing your message, you could request a relay by specifying the destination chain ID and receiver contract address. The relayers listen for these requests, fetch the corresponding VAA, and execute the transaction on the target chain, paying for gas themselves and being reimbursed by the user. This abstracts away gas complexities.

For developers, the key interfaces are the IWormhole core contract for publishing and verifying, and the IReceiver interface for destination contracts. Your destination contract must implement a function like receiveWormholeMessages to handle incoming verified payloads. Always validate the sourceChain and emitterAddress in this function to ensure messages are from your trusted source contract, preventing spoofing attacks. Start experimenting with the Quick Start in the docs.

This generic messaging capability unlocks advanced cross-chain designs: a DAO on Ethereum can execute treasury actions on Solana, a gaming asset on Polygon can trigger an event on Avalanche, or a DeFi protocol can aggregate liquidity across multiple networks in a single transaction. By moving beyond simple asset transfers, Wormhole GMP serves as the messaging layer for the interconnected appchain future.

development-tools
CROSS-CHAIN COMPOSABILITY

Essential Development Tools and SDKs

Build applications that interact with multiple blockchains using these core development kits and frameworks.

testing-strategy
TESTING AND SECURITY BEST PRACTICES

How to Experiment With Cross-Chain Composability

Cross-chain composability allows smart contracts on different blockchains to interact. This guide covers how to safely test these complex interactions using local environments, testnets, and security tools.

Cross-chain composability refers to the ability of decentralized applications (dApps) to interact with assets and logic across multiple blockchain networks. Unlike single-chain DeFi, cross-chain apps rely on bridges, messaging protocols (like LayerZero or Axelar), and oracles to synchronize state. Testing these interactions is critical because failures can lead to fund loss or protocol insolvency. The primary challenge is simulating the asynchronous, trust-minimized environment where a transaction on Chain A must reliably trigger an outcome on Chain B, often with significant latency and without a central coordinator.

Begin experimentation in a controlled, local environment. Use development frameworks like Foundry or Hardhat to deploy mock versions of cross-chain infrastructure on a local blockchain (e.g., Anvil). For example, you can create a simple MockBridge.sol contract that mimics a canonical bridge's locking and minting functions. This allows you to test your application's core logic for handling cross-chain messages and asset flows without relying on external, potentially unstable services. Tools like Chainlink's CCIP LocalSim or the Axelar Local Dev Environment provide more realistic sandboxes for specific protocols.

After local testing, graduate to public testnets. Deploy your contracts to chains like Sepolia, Goerli, Arbitrum Sepolia, and Polygon Mumbai. Use the testnet versions of production bridges (e.g., Wormhole Testnet, LayerZero's Sepolia Endpoint) to move test tokens and send messages. This stage tests integration with real, albeit non-production, infrastructure. Monitor transactions using cross-chain explorers like LayerZero Scan or Wormhole Explorer to verify message delivery and execution. This helps identify issues with gas settings, receiver contracts, and chain-specific quirks.

Security testing for cross-chain apps requires a multi-layered approach. Static analysis tools like Slither or Mythril can detect common vulnerabilities in your smart contracts. However, you must also test the composability itself. Write integration tests that simulate mainnet failure scenarios: - A bridge halting operations mid-transaction - A destination chain becoming congested or unavailable - A malicious actor spoofing a cross-chain message. Use fuzzing with Foundry's forge to input random, invalid data into your message-handling functions. Consider formal verification for critical state transition logic.

Finally, before any mainnet deployment, conduct audits and establish monitoring. Engage with specialized security firms that understand cross-chain vulnerabilities, such as reentrancy across chains or incorrect gas estimation for remote calls. Once live, implement circuit breakers and governance-controlled pause functions for your contracts. Use off-chain watcher services or The Graph to index and alert on failed cross-chain transactions. By methodically progressing from local mocks to audited mainnet deployment, developers can harness the power of cross-chain composability while significantly mitigating its inherent risks.

CROSS-CHAIN COMPOSABILITY

Frequently Asked Questions

Common technical questions and troubleshooting for developers building with cross-chain composability.

Cross-chain composability is the ability for decentralized applications (dApps) and their underlying components—like tokens, liquidity, or smart contract logic—to interact seamlessly across different blockchain networks. Unlike the native composability within a single chain (e.g., DeFi protocols on Ethereum), cross-chain composability connects isolated ecosystems.

It's critical because it unlocks liquidity and functionality trapped in silos. For example, a yield aggregator on Avalanche can source the best rates by accessing lending pools on Ethereum and Arbitrum. This expands user choice, improves capital efficiency, and enables novel applications like cross-chain collateralized debt positions. Without it, the multi-chain landscape remains fragmented, limiting innovation and user experience.

conclusion
EXPERIMENTAL FRAMEWORK

Conclusion and Next Steps

This guide has outlined the core concepts and tools for building cross-chain applications. The next step is to apply this knowledge through hands-on experimentation.

To solidify your understanding, start with a simple, low-risk project. Deploy a basic HelloWorld smart contract on two testnets, like Sepolia and Polygon Amoy. Use a bridge like the official Axelar GMP Sandbox or LayerZero's Omnichain Fungible Token (OFT) standard to send a message or token between them. This end-to-end flow teaches you the critical steps: setting up RPC endpoints, funding wallets with testnet gas on both chains, and handling asynchronous cross-chain callbacks.

As you build more complex logic, prioritize security and failure states. Your contracts must account for bridging latency, partial failures, and gas payment on the destination chain. Implement a robust retry mechanism and use a modular error handling pattern. For example, structure your contracts so failed messages can be manually rescued or refunded. Always audit the security assumptions of your chosen interoperability stack, as you are inheriting the trust model of its underlying validators or relayers.

The ecosystem is rapidly evolving. Stay current by monitoring key developments: the maturation of intent-based architectures (like Across and Socket), new shared security models (e.g., EigenLayer's AVS for interoperability), and advancements in zero-knowledge proofs for light client verification. Follow the documentation and governance forums of projects like Chainlink CCIP, Wormhole, and Hyperlane to understand new features and best practices. Your most valuable skill will be adapting to new primitives as they emerge.

Finally, engage with the community. Share your experiments, review others' code on GitHub, and participate in testnet incentive programs. Platforms like EthGlobal frequently host cross-chain hackathons, providing ideal environments to test your composable dApps under realistic conditions with expert support. The path from a simple cross-chain message to a sophisticated, multi-chain DeFi strategy is built through iterative experimentation, constant learning, and collaborative problem-solving.