Asterizm
  • What is Asterizm
    • Overview
    • Architecture
    • Benefits
    • Supported chains
      • Non-EVM chains integration plan
    • Frequently asked questions
    • White paper
    • GitHub
  • Infrastructure
    • Overview
    • Asterizm Connector
      • Client smart contract abstraction
      • Initializer smart contract
      • Translator smart contract
    • Client off-chain module
    • Asterizm Relayer
    • Asterizm Interfaces
      • IAsterizmConfigEnv
      • IConfig
      • IAsterizmEnv
      • IClientReceiverContract
      • IInitializerReceiver
      • IInitializerSender
      • IMultiChainToken
      • INonce
      • ITranslator
  • Guides
    • Transaction flow
    • Getting started
      • 1. Deploy your smart contracts
        • AsterizmDemo contract
        • Client contracts implementation logic
        • Solana integration logic
      • 2. Implement off-chain module
        • Simple implementation (shell script)
        • Default implementation (manual)
      • 3. Important! One final pre-flight check
    • External relays
      • Relay deployment and configuration
      • List of external relays
        • Chainlink
          • Mainnet
          • Testnet
    • Source chain notifications
    • Refund Logic
    • Error messages
      • EVM
        • Source chain
        • Destination chain
      • TVM and TON
      • Solana
    • Fee management
    • Code examples
    • Multi-Owner (Sender) System
  • Advanced
    • Best practices
    • Asset transfer
    • Debugging
  • Technical reference
    • Mainnet
    • Testnet
    • Smart contract audits
    • SDK
Powered by GitBook
On this page
  • Add a library
  • Import abstract contract
  • Call the class constructor
  • Adding trusted addresses
  • Sending messages
  • Receive and execute messages
  • Cross-chain data hashing logic
  • Estimating message fees
  • Upgradeable client contracts
  • You are almost there!
  1. Guides
  2. Getting started
  3. 1. Deploy your smart contracts

Client contracts implementation logic

Send and receive arbitrary messages between EVM and non-EVM chains

PreviousAsterizmDemo contractNextSolana integration logic

Last updated 2 months ago

To implement a smart contract, you need to extend it from the made by the Asterizm team.

IMPORTANT! The logic of Solana network integration differs significantly from the logic of integrating other networks, so you can read more in the about this chain.

Examples of client contract implementation can be found in the official repository -

Important! To support different types of networks we decided to convert all address variables to the uint format. It is necessary to take this into account when integrating the protocol.

To simplify the process, we have implemented the following libraries:

  • - for EVM

  • - for TVM

  • - for TON

The developer of the client contract must follow several steps:

Add a library

You need to add AsterizmProtocol library to your package.json: “asterizmprotocol”: “^1.0.1" and update packages - npm i

Import abstract contract

You need to import an into your contract: For EVM: import "asterizmprotocol/contracts/evm/AsterizmClient.sol" (you can also use import "asterizmprotocol/contracts/evm/AsterizmClientUpgradeable.sol" for upgradeable client contracts, ) For TVM and TON: import "asterizmprotocol/contracts/tvm/AsterizmClient.tsol"

Call the class constructor

Adding trusted addresses

A list of trusted addresses must be populated for the system. This list contains trusted contract addresses for each supported network. This is done by one of two methods:

addTrustedAddress(uint64 _chainId, uint _trusterAddress)

addTrustedAddresses(uint64[] _chainId, uint[] _trusterAddress)

Sending messages

To initialize the transfer event you need to call the transfer initialization method:

For EVM: _initAsterizmTransferEvent(uint64 _dstChainId, bytes _payload)

For TVM and TON: _initAsterizmTransferEvent(uint64 _dstChainId, TvmCell _payload)

Examples of transfer initialization:

Receive and execute messages

You need to implement _asterizmReceive() method to receive and execute data in the destination network. This method accepts one _dto parameter type ClAsterizmReceiveRequestDto, which contains all transfer data.

To retrieve the transferred instructions, the _dto.payload parameter must be decoded into the originally transferred data type, for example using the abi.decode()method.

IMPORTANT!

For EVM networks only.

You need to implement the _buildPackedPayload()method. This method is necessary for the internal protocol logic to convert your payload from abi.encode() format into abi.encodePacked(). This conversion is necessary to implement cross-chain hashing.

Cross-chain data hashing logic

Asterizm protocol has a universal cross-chain data hashing logic. It is required to check the validity and integrity of the data transferred within a cross-chain transaction.

EVM

TVM and TON

In TVM networks there are several versions of the hashing implementation, so you have to choose the version based on your requirements:

  • buildCrosschainHashV1()- this version of hashing implementation is relatively cheap, but it has a nuance - if your payload involves sending such data types as bytes or string, you should add these data to the very end of the list when packing (abi.encode()) otherwise hash validation errors may occur in the destination network. Use this method if you do not need to send a large number of bytes or string parameters, or to save on gas.

  • buildCrosschainHashV2()- this version of hashing has a much higher gas price but avoids the problem of the first version related to the position of bytes and string data in your payload. Use this version if you need to send bytes or string data types.

IMPORTANT!

In case you perform cross-chain transfer between different types of networks (EVM->TVM/TON, TVM/TON->EVM) it is strongly recommended not to use bool type in payload parameters. Otherwise, validation of transfer integrity in the destination network will fail.

Estimating message fees

Upgradeable client contracts

The protocol allows for the creation of upgradable client contracts on EVM networks, enabling the separation of system logic and data at the contract level.

Here is an example of how to implement an upgradable contract:

You are almost there!

Call constructor of base client contract setting of necessary parameters: For EVM: AsterizmClient(IInitializerSender _initializerLib, bool _useForceOrder, bool _disableHashValidation) For TVM and TON: In this network, the constructor does not take any parameters as input, instead static parameters are used initializerLib_, useForceOrder_, disableHashValidation_ initializerLib - initializer contract address (see the ), useForceOrder - flag of strict message order (see ), disableHashValidation - disable transfer hash validation flag (see )

_dstChainId - destination network ID (see the ), _payload - instructions encoded in bytes, for example with abi.encode() method

Please note: it is not necessary to specify a contract address in the destination network - it is taken from the list of trusted addresses (read ).

The protocol currently supports the following network types: and . Asterizm independently selects the hashing method depending on what types the source and destination networks are at the abstraction level of the client smart contract.

an example of hashing implementation for EVM networks.

As mentioned above, in EVM networks you need to implement the method _buildPackedPayload() - .

Check (TVM) and (TON) an example of hashing implementation for TVM and TON networks.

Congratulations! The contracts for messaging in the required networks are ready and can be deployed to the

To understand the payment process and the calculation of cross-chain transaction fees, please see the

To implement an upgradable client contract, you should inherit from"asterizmprotocol/contracts/evm/AsterizmClientUpgradeable.sol" , and instead of using a contract constructor you should utilize a special initialization function as follows: function initialize(IInitializerSender _initializerLib) initializer public { __AsterizmClientUpgradeable_init(_initializerLib, true, true); }

Get ready to make your transactions confidential using the - you will learn how to set it up in the .

abstract class
Solana integration section
https://github.com/Asterizm-Protocol/asterizm-contracts-evm/tree/master/contracts/demo
https://github.com/Asterizm-Protocol/asterizm-contracts-evm/tree/master/contracts/libs
https://github.com/Asterizm-Protocol/asterizm-contracts-tvm/tree/master/contracts/libs
https://github.com/Asterizm-Protocol/asterizm-contracts-ton/tree/master/contracts/libs
Asterizm abstract client contract
example
list of supported networks
Best practices
Best practices
list of supported networks
EVM
TVM
Check out
example
this
this
networks supported by Asterizm
Fees management section
contract abstraction
Client off-chain module
next section
Adding trusted addresses
Logoasterizm-contracts-evm/contracts/demo/AsterizmDemo.sol at master · Asterizm-Protocol/asterizm-contracts-evmGitHub
EVM contracts
Logoasterizm-contracts-tvm/contracts/demo/AsterizmDemo.tsol at master · Asterizm-Protocol/asterizm-contracts-tvmGitHub
TVM contracts
Logoasterizm-contracts-ton/contracts/demo/AsterizmDemo.tsol at master · Asterizm-Protocol/asterizm-contracts-tonGitHub
TON contracts