Cross-Chain & Interoperability

InteroperabilityFree Lesson

Advertisement

Cross-Chain & Interoperability

Bridges, cross-chain messaging, interoperability protocols, and multi-chain.

Overview

Cross-chain enables communication between blockchains.

Bridge Types

TypeDescription
Lock & MintLock assets, mint wrapped
Burn & MintBurn on one, mint on other
Atomic SwapExchange across chains
RelayCross-chain messages

Simple Bridge Contract

// Source chain
contract BridgeSource {
    mapping(bytes32 => bool) public processed;
    
    event Locked(address user, uint256 amount, uint256 targetChain);
    
    function lock(uint256 amount, uint256 targetChain) public {
        require(token.transferFrom(msg.sender, address(this), amount));
        
        bytes32 txHash = keccak256(abi.encodePacked(msg.sender, amount, targetChain, block.timestamp));
        processed[txHash] = true;
        
        emit Locked(msg.sender, amount, targetChain);
    }
}

// Destination chain
contract BridgeDestination {
    mapping(bytes32 => bool) public processed;
    
    function mint(address to, uint256 amount, bytes32 proof) public {
        require(!processed[proof]);
        require(verifyProof(proof));
        
        processed[proof] = true;
        token.mint(to, amount);
    }
}

Cross-Chain Messaging

// LayerZero style
contract CrossChainApp {
    function sendMessage(uint16 _dstChainId, bytes calldata _message) public {
        // Encode message
        bytes memory payload = abi.encode(msg.sender, _message);
        
        // Send cross-chain
        lzSend(_dstChainId, payload, payable(msg.sender), address(0), "", 0);
    }
    
    function lzReceive(uint16 _srcChainId, bytes calldata _message) public {
        (address sender, bytes memory message) = abi.decode(_message, (address, bytes));
        
        // Process received message
    }
}

Interoperability Protocols

ProtocolType
LayerZeroMessaging
AxelarCross-chain
WormholeBridge
IBCCosmos standard

Best Practices

  1. Security audits — Bridge vulnerabilities
  2. Finality checks — Confirm transactions
  3. Rate limiting — Prevent exploits
  4. Monitoring — Track bridge activity

Practice

Build a simple token bridge between two chains.

Advertisement

Need Expert Blockchain Help?

Get personalized Web3 training or smart contract consulting.

Advertisement