Bridge Service
The bridge service is a component that facilitates token transfers and enables cross-shard calls between different blockchains. This section focuses on the transfer of NEAR tokens from the Mainnet to a Calimero shard as an example use case.
Workflow Diagram
This provides a visual representation of the token transfer process
Token Transfer Workflow
The transfer of NEAR tokens from the Mainnet to a Calimero shard involves the following steps:
Lock Method on NEAR Mainnet
The token transfer process begins when a user or application initiates a token transfer by invoking the lock method on the fungible token (FT) contract deployed on the NEAR Mainnet. This method locks the desired amount of NEAR tokens.
Proof Retrieval from NEAR Mainnet
Once the transaction is completed on the NEAR blockchain, the bridge service identifies the token transfer event by monitoring a message queue. It then performs an RPC call to an archival node on the NEAR Mainnet to obtain the proof of this transaction.
Relaying Latest Block to Calimero Shard
Simultaneously, the NEAR to Calimero relayer, operating independently from the bridge service, receives a notification of the token transfer event through the message queue. The relayer then relays the latest block from the NEAR Mainnet to the light client contract deployed on the Calimero shard.
Mint Method on FT Contract on Calimero Shard
With the proof of NEAR token lock on the Mainnet, the user or application can call the mint method on the FT contract deployed on the Calimero shard. This method facilitates the minting of wrapped NEAR tokens on the Calimero shard, representing the equivalent amount of locked NEAR tokens on the Mainnet.
Prover Contract Verification on Calimero Shard
The Prover contract deployed on the Calimero shard plays a critical role in verifying the proof. It compares the expected block Merkle root, obtained from the light client contract and supplemented with valid block headers from the NEAR Mainnet, with the calculated block Merkle root.
Minting Wrapped NEAR on Calimero Shard
If the computed block Merkle root matches the expected value, the Prover contract on the Calimero shard confirms the validity of the proof. Consequently, wrapped NEAR tokens can be minted on the Calimero shard, representing the locked NEAR tokens on the Mainnet.
By following this token transfer workflow, the bridge service facilitates secure and seamless transfers of fungible tokens between different blockchain networks.