Implementation

Core Concepts

Chain-Agnostic Tokens are created with two key components:

  1. Deploying the same token contracts on multiple chains

  2. Configuring each token contract with trusted emitters

What is an 'trusted emitter'? A trusted emitter is a piece of information within each token contract, that specifies which chains the CAT has been deployed on. The trusted emitter is used to verify that messages between chains are only emitted by trusted CAT contracts.

When Chain-Agnostic Tokens are being transferred from one chain to another, it harnesses the power of generic messaging using Wormhole.

What is 'generic messaging' in simple terms? Generic messaging is when a message is passed from one blockchain to another. A message can only be sent to the destination blockchain once it is checked and validated.

Wormhole's Guardian network — 19 validators who run a set of distributed notes on all connected blockchains — independently observe and verify messages that are sent from one chain to another.

Once verified, a final signature is formed by combining these isolated results from different Guardians confirming that an event has been observed and witnessed by at least two thirds of the Wormhole Guardians to reach a consensus. This signature is called a VAA (Verifiable Action Approval). A VAA is then taken to the destination chain by a Relayer and the action is executed.

For more: The Wormhole Book

How a CAT is transferred between chains

Nexa provides interface specifications for both ERC20 and ERC721 tokens. Projects can implement these interfaces to get out-of-the-box xAsset behavior and deploy themselves on all the chains. Nexa also provides an easy to use user interface to deploy these contracts on protocol's behalf and xMint the token/NFT.

These interfaces contain pre-built functionality to move the tokens/NFTs across chains using the following two functions:

  • bridgeOut

  • bridgeIn

function bridgeOut( uint256 tokenId, uint16 chainId, address recipient, uint32 nonce)

This function burns or locks the token amount on the origin chain (Chain A) depending on the implementation (CAT V1 or CAT V2). Then, it publishes a generic message using Wormhole. Once Wormhole's Guardian network verifies the action, the VAA (Verified Action Approval) can then be posted to bridgeIn function on the destination chain (Chain B).

function bridgeIn(bytes calldata encodedVM)

The VAA is posted to Chain B. This function parses the message (payload) to extract the information such as:

  • Which token contract and blockchain the message is from (Chain A)

  • Which wallet is the recipient

  • The amount that needs to be transferred

If the contract that emitted this message is a trusted emitter, the destination contract will mint the same token amount on Chain A and send it to the recipient's address, completing the bridge transaction.

Last updated