Think in Coin | DEV Docs
  • Develop Documents
  • Networks
    • Fantom Network
      • quick-start
        • Short Guide
      • technology
        • Lachesis aBFT
        • Overview
        • Proof of Stake
        • Transaction Fees
        • FAQ
      • staking
        • Quick start
        • Overview
        • Stake on Fantom
        • Run a Validator Node
        • Run a Read-only node
        • Run a Testnet Validator
        • Troubleshooting
      • api
        • Public API endpoints
        • Getting Started
        • Installation
        • GraphQL Schema Basics
        • Schema Structure
        • Implementation Details and Notes
        • Covalent indexing and querying API
      • tutorials
        • Set up Metamask
        • Set up Metamask (testnet)
        • Deploy a Smart Contract
        • Create a Fixed-cap Asset
    • xDAI Chain
      • Welcome to xDai
      • untitled
        • About xdai
          • Projects & DApps
          • Features
          • Use Cases
          • News & Information
          • Roadmaps
          • FAQs
        • For users
          • xDai Token
          • Getting Started with xDai
          • Bridges
          • Wallets
          • Applications
          • Block Explorers
          • Governance
        • For stakers
          • STAKE Token
          • Staking on xDai
          • EasyStaking on Ethereum
          • POSDAO Staking Roadmap
        • For developers
          • Developer Resources & Tools
          • On-Chain Random Numbers
          • Install xDai Client - Run a Non-Validator Node
          • Stable Chain Network Deployment
          • Grants for building on xDai
          • Immunefi Bug Bounty
        • For validators
    • Polygon Network
      • About - Polygon
      • Technology
    • Huobi HECO Chain
      • Huobi Open Platform
    • Binance Chain
      • Create Address
      • Fees
      • Governance
      • Threshold Signature Scheme
      • Atomic Swap
      • WalletConnect
      • Wallets Support
        • WalletConnect Support
        • Trust Wallet User Guide
        • Ledger Wallet Guide
        • Trezor Wallet Guide
        • How to manage BEP8 token with Web Wallet
      • BEP8 Token Protocol
      • Binance DEX Trading
      • Binance Chain Testnet
      • Exchange Integration
      • List Instructions
    • Binance Smart Chain
      • Concepts
        • Consensus
        • Comparison
        • Genesis File
        • BC > BSC Cross-Chain
          • Mechanism
          • Cross-Chain Transfer
          • BSC Relayer
          • Oracle Module
          • Oracle Relayer
          • Relayer incentives
        • Build-in System Contract
        • Governance
      • Ecosystem
      • Gnosis
      • Binance Bridge
        • Release
        • Roadmap
        • User Guides
        • Developer
          • Widget
          • Swagger API reference
        • Partnership
        • Support
          • Customer Support
        • guides
          • Binance Bridge v2
          • Binance Bridge v1
          • Supported Assets
          • Buy BNB as Gas
    • Ethereum (ERC)
      • Ether - Introduction
        • The Ethereum Foundation
        • Community
        • History of Ethereum
        • The Homestead Release
        • What is Ethereum?
        • A platform for decentralized apps
      • The Ethereum network
        • Connecting to the Network
        • Test Networks
      • Mining
      • Contracts and Transactions
        • Account Types, Gas, and Transactions
        • Contracts
        • Accessing Contracts and Transactions
        • Dapps
        • Mix
          • Project Editor
          • Scenarios Editor
          • State Viewer
          • Transaction Explorer
          • JavaScript console
          • Transaction debugger
          • Dapps deployment
          • Code Editor
        • Ethereum Tests
          • Blockchain Tests
          • State Tests
        • Web3 Base Layer Services
    • Harmony ONE
      • developers
        • Getting Started
        • Network & Faucets
        • Deploying on Harmony
        • SDK
        • API
        • Wallets
        • Tools
        • Showcases
        • Hackathon & Bounties
        • Learn
      • network
        • Governance
        • Holders
        • Validators
        • Delegators
      • general
        • Grants
        • Introduction
          • What is Harmony?‌
          • Roadmap
          • Strategy & Architecture
          • Study Materials
          • FAQ
        • Technology
        • Horizon Bridge
        • DApps
        • Ecosystem
        • Community
    • TRON Network (TRC)
      • Introduction
      • Tron Protocol
        • Account
        • Resource Model
        • Super Representatives
          • Mechanism
          • Step to become a Candidate
          • Committee and Proposal
        • Transaction
        • Multi-Signature
          • Example Process Flow
        • Concensus
        • untitled
          • Build transaction locally
      • TRX AND TRC TOKEN
        • TRX
          • TRX Transfer
          • Query TRX balance
        • TRC-10
          • Issue TRC-10 token
          • Participate TRC-10
          • TRC-10 Transfer
          • Query TRC-10 balance
          • TRC-10 Transfer in Smart Contracts
          • Other TRC-10 Interfaces
        • TRC-20
          • Protocol Interface
          • Issuing TRC-20 tokens tutorial
          • TRC-20 Contract Interaction
        • TRC-721
  • Community
    • Github
    • Telegram DEVs
Powered by GitBook
On this page
  • Monitor and Parse Cross Chain Event
  • Build Tendermint Header and Query Cross Chain Package
  • Query Cross Chain Package With Merkle Proof
  • Call Build-In System Contract
  • Deliver Cross Chain Package
  • Incentives Mechanism

Was this helpful?

  1. Networks
  2. Binance Smart Chain
  3. Concepts
  4. BC > BSC Cross-Chain

BSC Relayer

PreviousCross-Chain TransferNextOracle Module

Last updated 2 years ago

Was this helpful?

Relayers are responsible to submit Cross-Chain Communication Packages between the two blockchains. Due to the heterogeneous parallel chain structure, two different types of Relayers are created.

Relayers for BC-to-BSC communication referred to as BSC Relayers are a standalone process that can be run by anyone, and anywhere, except that Relayers must register themselves onto BSC and deposit a certain amount of BNB. Only relaying requests from the registered Relayers will be accepted by BSC.

GitHub Implementation link: ​

Config Files: ​

Monitor and Parse Cross Chain Event

As a BSC relayer, it must have proper configurations on the following three items:

A BSC relayer is required to parse all block results and pick out all events with event type “IBCPackage” from endBlock event table. This is an cross chain package event example:

{  "type": "IBCPackage",  "attributes":  [    {      "key": "IBCPackageInfo",      "value": "96::8::19"    }  ]}

BSC relayer should iterate all the attributes and parse the attribute value:

  1. Split the value with “::” and get a 4-length string array

  2. Follow the following table to parse the 4 elements:

  3. Filter out attributes with mismatched destination chain CrossChainID.

Build Tendermint Header and Query Cross Chain Package

import tmtypes "github.com/tendermint/tendermint/types"type Header struct {  tmtypes.SignedHeader  ValidatorSet     *tmtypes.ValidatorSet `json:"validator_set"`  NextValidatorSet *tmtypes.ValidatorSet `json:"next_validator_set"`}

If a cross chain package event is found at height H, wait for block H+1 and call the following rpc methods to build the above Header object:

Header Encoding in golang:

  1. Example golang code to encode Header:

    import (  amino "github.com/tendermint/go-amino"  tmtypes "github.com/tendermint/tendermint/types")​var cdc = amino.NewCodec()​func init() {  tmtypes.RegisterBlockAmino(cdc)}​func EncodeHeader(h *Header) ([]byte, error) {  bz, err := cdc.MarshalBinaryLengthPrefixed(h)  if err != nil {     return nil, err  }  return bz, nil}

Query Cross Chain Package With Merkle Proof

  1. Query height: H

  2. Query path: /store/ibc/key

  3. Follow the table to build a 14-length byte array as query key:

  4. Assemble the above parameters to the following rpc call.

    {rpcEndpoint}/abci_query?path={queryPath}&data={queryKey}&height={queryHeight}&prove=true

Call Build-In System Contract

  • function syncTendermintHeader(bytes calldata header, uint64 height)

    Call syncTendermintHeader of TendermintLightClient contract to sync BC header. The contract address is 0x0000000000000000000000000000000000001003. The “header” is the encoding result of Header and the height should be H+1

Deliver Cross Chain Package

Call handlePackage of crosschain contract(0x0000000000000000000000000000000000002000) to deliver the cross chain packages:

Incentives Mechanism

Add dependency on ​

Add dependency on :

​​

https://github.com/binance-chain/bsc-relayer
https://github.com/binance-chain/bsc-relayer-config
go-amino v0.14.1
tendermint v0.32.3
BSC Relayer Incentive Mechanism