# Transaction flow

<figure><img src="https://617807107-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwQVWr0SwpsQAvHutQCC9%2Fuploads%2FAexbkzbf0hPidGBsTSi7%2FAsterizm%20solution%20logic%20scheme%20(1).png?alt=media&#x26;token=ddcfb60b-b88a-4510-ad00-83e638faee9d" alt=""><figcaption><p>Asterizm architecture</p></figcaption></figure>

***packet*** - data packet containing cross-chain transaction content and related parameters;

**payload** - message/data transmitted as part of a cross-chain transaction;

***dst*** - destination network ID;

***xID*** - a unique cross-chain transaction ID generated when the cross-chain transaction is initialized  in the `_initAsterizmTransferEvent()` method;

***p*** - additional parameters of the transaction: address of the source contract, destination contract, timestamp, and other data.

{% hint style="info" %}
Complete information can be found in Section 2 of the [White paper](https://asterizm.io/files/wp.pdf)
{% endhint %}

### Step 1

The client implements a smart contract using an [abstract class from Asterizm](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) and deploys it to the required networks. \
The <mark style="color:orange;">`_initAsterizmTransferEvent()`</mark> method is used to initiate a cross-chain transaction on the contract. The data and parameters of the cross-chain transaction are transmitted to it.&#x20;

The transaction can contain arbitrary information and one or more actions (instructions) to be performed on the destination networks.

### Step 2

The [client smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) sends the received data and hash based on the payload generated at that moment **xID**, source chain id, destination chain id, client smart contract address in the source and destination chains.

{% hint style="info" %}
At this step, the key parameters are formed, which will further ensure the security of the cross-chain transaction, namely to confirm its validity and integrity in the destination chain.
{% endhint %}

### Step 3

The [Client off-chain module](https://docs.asterizm.io/infrastructure/client-off-chain-module) receives the cross-chain transaction payload and initiates the cross-chain transaction by calling `initAsterizmTransfer()` on the client's smart contract in the source network.

### Step 4

Before sending transaction proofs (**hash** and **xID**) to the [Initializer contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract), the [Сlient s smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) performs a validity and integrity check of the transaction by comparing the hash, calculated based on the payload. \
This effectively mitigates the risk of spam and counterfeit transactions in case of compromise of the [Client server](https://docs.asterizm.io/infrastructure/client-off-chain-module).

{% hint style="success" %}
This step verifies that this exact transaction was initiated on the [client's smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction), which eliminates the possibility of spam from the [client's off-chain module](https://docs.asterizm.io/infrastructure/client-off-chain-module).
{% endhint %}

### Step 5

The [Initializer smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract) checks the transaction nonce to preserve the cross-chain transaction execution sequence and transmits the transaction proofs (**hash** and **xID**) with the unique parameters to the [Translator smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/translator-smart-contract).

{% hint style="info" %}
When a data packet is received on the [Initializer smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract), the client is identified based on the destination  chain id, the Client smart contract address in the destination chain, and the client smart contract address in the source chain.

After the client (sender) of the cross-chain transaction is determined, the nonce value is incremented for it.
{% endhint %}

### Step 6

[Asterizm Relayer servers](https://docs.asterizm.io/infrastructure/asterizm-relayer) pull the proofs with the parameters from the [Translator contract](https://docs.asterizm.io/infrastructure/asterizm-connector/translator-smart-contract) and send them to the [Translator smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/translator-smart-contract) in the destination network for further processing.

### Step 7

The [Translator smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/translator-smart-contract) on the destination network accepts the encrypted data with the parameters from the [Relayers](https://docs.asterizm.io/infrastructure/asterizm-relayer) and passes it to the [Initializer smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract) for validation.

### Step 8

After receiving the proofs and the parameters, the [Initializer smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract) checks the nonce to comply with the transaction sequence, stores the transaction **xID** to validate the transaction at step 10, and transmits the proofs to the [Client’s smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction).

### Step 9

The [Client's smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) in the destination network receives the proofs with the parameters and emits an event to notify the delivery of proofs, which is awaited by the [Client's off-chain module](https://docs.asterizm.io/infrastructure/client-off-chain-module).

{% hint style="success" %}
At this stage, the first but not the main step of transaction validity check occurs - the hash from the payload and the transaction's xID are compared, mitigating the risk of [relay server](https://docs.asterizm.io/infrastructure/asterizm-relayer) compromise.
{% endhint %}

### Step 10

After the first step of cross-chain transaction validation, the [client’s server](https://docs.asterizm.io/infrastructure/client-off-chain-module) initiates the transaction on the [Client’s smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) by calling the <mark style="color:orange;">`asterizmClReceive()`</mark> method in the destination network, sending the **payload** (data) and **xID** to the contract, and validating the transaction on the [Initializer smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract) by calculating the hash from received **payload** and checking the **xID**.

{% hint style="success" %}
At this step, the integrity of the data and the trusted addresses is checked before the transaction is executed. This check eliminates the risk of hacking the [client’s server](https://docs.asterizm.io/infrastructure/client-off-chain-module).
{% endhint %}

{% hint style="info" %}
The verification is performed by calculating and matching the hash from the payload with the hash received from [Relayers](https://docs.asterizm.io/infrastructure/asterizm-relayer) and the xID that was previously stored on the [Initializer contract](https://docs.asterizm.io/infrastructure/asterizm-connector/initializer-smart-contract). If the verification succeeds, it means that the [client’s contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) executes exactly the transaction it sent, and does so for the first time. This algorithm eliminates the possibility of spamming transactions and spoofing data on the [client’s server](https://docs.asterizm.io/infrastructure/client-off-chain-module) (if, for example, the server is compromised).
{% endhint %}

### Step 11

After receiving the confirmation of the validity and integrity of the cross-chain transaction, the [client’s smart contract](https://docs.asterizm.io/infrastructure/asterizm-connector/client-smart-contract-abstraction) executes the **payload** or data sent in the cross-chain transaction, calling methods of other contracts or performing calculations on the client’s contract. \
The logic of this step depends solely on the client’s business logic implemented in the cross-chain transaction.
