Documentation
  • 🌅Getting Started
    • Introduction
    • Motivation
    • Official Links
  • 🌐VIA Omnichain Network
    • Technology Overview
    • Contract Configuration
    • Gateway Contracts
    • Validation Cloud
    • Fees
    • Examples
    • Add Your Blockchain
  • 🔋Supported Protocols
    • Bridged USDC Standard Onboarding
      • Contracts We Deploy
      • Blockchain Responsibilities
    • Proto-USD
      • Background FAQs
      • Key Features
      • Build With Proto-USD
      • Proto Gateway Addresses
      • Fee Management
      • Gas Reimbursement Mechanism
  • 💻Security
    • Network Validator Intro
    • Layered Security
    • Become a Network Validator
  • 📸Marketing
    • Branding Assets
    • Co-Promotion
  • 🎬Presentations
    • Overview
  • 🏪Additional Products
    • TokenWorx
  • 💡Additional Information
    • Contact us
    • VIA Token
    • Audits
    • Disclaimer
    • Legacy
      • Legacy Contracts
      • PAPER
Powered by GitBook
On this page
  1. VIA Omnichain Network

Contract Configuration

To enable cross-chain communication in your blockchain application, you need two key functions: sendMessage() and messageProcess(). These functions handle sending and receiving messages between different blockchains.

Simple Code Example

Here's a straightforward example to demonstrate the simplicity of using these functions:

pragma solidity 0.8.17;

import "@vialabs-io/contracts/message/MessageClient.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

contract HelloERC20 is ERC20Burnable, MessageClient {
    constructor() ERC20("HelloERC20", "HELLO") {
        _mint(msg.sender, 1_000_000 ether);
    }

    function bridge(uint _destChainId, address _recipient, uint _amount) external onlyActiveChain(_destChainId) {
        // burn tokens
        _burn(msg.sender, _amount);

        // send cross chain message
        _sendMessage(_destChainId, abi.encode(_recipient, _amount));
    }

    function messageProcess(uint, uint _sourceChainId, address _sender, address, uint, bytes calldata _data) external override  onlySelf(_sender, _sourceChainId)  {
        // decode message
        (address _recipient, uint _amount) = abi.decode(_data, (address, uint));

        // mint tokens
        _mint(_recipient, _amount);
    }
}

The sendMessage()function packages and sends data to another blockchain.

Parameters:

  • destinationChainId: The ID of the chain to send the message to.

  • data: The message data to be sent.


The messageProcess() function receives and processes data from another blockchain.

Parameters:

  • _txId: Transaction ID of the message.

  • _sourceChainId: ID of the source chain from where the message is coming.

  • _sender: Address of the sender.

  • _reference: Reference address.

  • _amount: Amount of tokens involved in the message.

  • _data: Additional message data.


This simple example shows how easy it is to set up cross-chain communication using the VIA Network.

PreviousTechnology OverviewNextGateway Contracts

Last updated 8 months ago

Developers can use the to dive further into these functions.

🌐
Developer Documentation