# AsterizmDemo contract

To demonstrate the functionality of our protocol, our team has developed a demo contract that facilitates the transmission of text data between networks. You can find the contract code in our repositories (both the basic and upgradeable versions for EVM and the basic version for TVM networks):

{% embed url="<https://github.com/Asterizm-Protocol/asterizm-contracts-evm/blob/master/contracts/demo/AsterizmDemo.sol>" %}
EVM base demo contract
{% endembed %}

{% embed url="<https://github.com/Asterizm-Protocol/asterizm-contracts-evm/blob/master/contracts/demo/AsterizmDemoUpgradeableV1.sol>" %}
EVM upgradeable demo contract
{% endembed %}

{% embed url="<https://github.com/Asterizm-Protocol/asterizm-contracts-tvm/blob/master/contracts/demo/AsterizmDemo.tsol>" %}
TVM demo contract
{% endembed %}

{% embed url="<https://github.com/Asterizm-Protocol/asterizm-contracts-ton/blob/master/contracts/demo/AsterizmDemo.tsol>" %}
TON demo contract
{% endembed %}

{% embed url="<https://github.com/Asterizm-Protocol/asterizm-contracts-sol/tree/master/programs/asterizm-value-example>" %}
Solana demo program
{% endembed %}

To complete the full configuration, you need to perform the following steps:

1. Deploy the contracts to the required networks and obtain their addresses. This can be done on both [Testnet](/technical-reference/testnet.md), and [Mainnet](/technical-reference/mainnet.md)
2. Add the obtained addresses to the list of trusted addresses on each network.
3. Send a message containing text from one network to another.

## Contract deployment

Here are console commands for simplified deployment

#### EVM

{% code overflow="wrap" %}

```bash
npx hardhat demo:deploy {initializerAddress} {relayAddress?} {feeTokenAddress?} --network {networkName}
```

{% endcode %}

The command accepts the following parameters:

* **initializerAddress** - mandatory parameter: the address of the initializer on the network. You can review the list of available addresses on the respective pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **relayAddress** - optional parameter: the address of an external relay. You will be able to review the list of available external relays on the [respective page](/guides/external-relays/list-of-external-relays.md)
* feeTokenAddress - optional parameter: token address for  transfer commission payment
* **networkName** - mandatory parameter: the name of the network to which the contract is deployed. You can explore the list of available networks [here](https://github.com/Asterizm-Protocol/asterizm-contracts-evm/blob/master/hardhat.config.ts#L41).

Upon successful execution, the command will return a response similar to the following (the address of the demo contract will be displayed under the **AsterizmDemo address**):

```bash
Deployment was done.

Total gas limit: 2556349
Owner address: 0xf9E3b4AC4CEFF24464840c426E7e3506dC145c44
Initializer address: 0xFE1B8bc850E34F260A08d41dd034b0fb82EfE45a
AsterizmDemo address: 0x50c7297E385afCC365deD9069a346694107442F0
```

#### TVM

{% code overflow="wrap" %}

```bash
npx locklift run --script ./scripts/demo/demo_deploy_task.ts --initializer {initializerAddress} --externalRelay {relayAddress?} --network {networkName}
```

{% endcode %}

The command accepts the following parameters:

* **initializerAddress** - mandatory parameter: the address of the initializer on the network. You can review the list of available addresses on the respective pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **relayAddress** - optional parameter: the address of an external relay. You will be able to review the list of available external relays on the [respective page](/guides/external-relays/list-of-external-relays.md)
* **networkName** - mandatory parameter: the name of the network to which the contract is deployed. You can explore the list of available networks [here](https://github.com/Asterizm-Protocol/asterizm-contracts-tvm/blob/master/locklift.config.ts#L41)

Upon successful execution, the command will return a response similar to the following (the address of the demo contract will be displayed under the **AsterizmDemo address**):

```bash
Deployment was done.

Owner address: 0:68a73acf79fed327d33a1e60503060021cbc2d9e1e8500d073d448d9a74f978f
Initializer address: 0:c100d8e7100822e6e5b9169c1423686bb99eb011eb37798232b3a2cedf4ecf08
AsterizmDemo address: 0:d70fd67d3de5f447b35d79a9c51b9d721c45c9eabdf9cafdd894fa17425bea9f
```

#### TON

***Coming soon***&#x20;

#### Solana

Build programs:

```bash
anchor build
```

Deploy demo program:

```bash
solana program deploy ./target/deploy/asterizm_value_example.so
```

Initialization client config logic (If successful, the command will not output anything. In case of an error, a log will be displayed):

```bash
npx ts-node scripts/settings/6-initialize-client-settings.ts
    Local chain ID: {localChainId}
    Solana Endpoint: {solanaEndpoint}
```

The command accepts the following parameters:

* **localChainId** - mandatory parameter: local chain ID. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **solanaEndpoint** - solana rpc url

Client account creation (If successful, the command will not output anything. In case of an error, a log will be displayed):

```bash
npx ts-node scripts/settings/7-create-client-account.ts
    Solana Endpoint: {solanaEndpoint}
```

The command accepts the following parameters:

* **solanaEndpoint** - solana rpc url

Client sender creation (If successful, the command will not output anything. In case of an error, a log will be displayed), the address created after executing this command will need to be added to the trusted addresses in other networks:

```bash
npx ts-node scripts/settings/9-create-client-sender.ts
    Solana Endpoint: {solanaEndpoint}
```

The command accepts the following parameters:

* **solanaEndpoint** - solana rpc url

Client demo program sender creation (If successful, the command will not output anything. In case of an error, a log will be displayed):

```bash
npx ts-node scripts/settings/10-value-init-create-client.ts
    Solana Endpoint: {solanaEndpoint}
```

The command accepts the following parameters:

* **solanaEndpoint** - solana rpc url

## Adding Trusted Addresses

To simplify the process of adding trusted addresses, console commands have been developed.

{% hint style="info" %}
IMPORTANT!

In each network, it is essential to add the trusted address of those networks to which transfers will be sent. That is if you plan to send such transfers:

* Ethereum -> Polygon
* Ethereum -> BSC
* Polygon -> Ethereum
* BSC -> Ethereum

then you should add a total of 4 trusted addresses as follows:

* In the Ethereum network, add 2 trusted addresses (Polygon and BSC)
* In the Polygon network, add 1 trusted address (Ethereum)
* In the BSC network, add 1 trusted address (Ethereum)&#x20;
  {% endhint %}

#### EVM

{% code overflow="wrap" fullWidth="false" %}

```bash
npx hardhat deploy:addTrustedAddress {trustedChainId} {trustedAddress} {contractAddress} demo --network {networkName}
```

{% endcode %}

The command accepts the following parameters:

* **trustedChainId** - mandatory parameter: the ID of the network of the trusted address. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **trustedAddress** - mandatory parameter: the address of the trusted demo contract. You will be able to review the list of available external relays later on a dedicated page. Please note that this parameter accepts a **uint** value, not **address**. Therefore, you will need to convert the hexadecimal address to decimal
* **contractAddress** - mandatory parameter: the address of the demo contract in the current network
* **networkName** - mandatory parameter: the name of the source network. You can check the list of available networks [here](https://github.com/Asterizm-Protocol/asterizm-contracts-evm/blob/master/hardhat.config.ts#L41).

Upon successful execution, the command will return a response similar to the following:

```bash
Added trusted address successfully

Total gas limit: 116817
Target contract address: 0x50c7297E385afCC365deD9069a346694107442F0
Transaction hash: 0x8f131674d51e12a213908a81e969feef4010cbfa2dbcbd1b19310b9c6301880f
```

#### TVM

<pre class="language-bash" data-overflow="wrap"><code class="lang-bash"><strong>npx locklift run --script ./scripts/deploy_singletrustedaddress_task.ts --contractAddress {contractAddress} --trustedChainId {trustedChainId} --trustedAddress {trustedAddress} --network {networkName}
</strong></code></pre>

The command accepts the following parameters:

* **contractAddress** - mandatory parameter: the address of the demo contract in the current network
* **trustedChainId** - mandatory parameter: the ID of the network of the trusted address. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **trustedAddress** - mandatory parameter: the address of the trusted demo contract. You will be able to review the list of available external relays later on a dedicated page. Please note that this parameter accepts a **uint** value, not **address**. Therefore, you will need to convert the hexadecimal address to decimal
* **networkName** - mandatory parameter: the name of the source network. You can check the list of available networks [here](https://github.com/Asterizm-Protocol/asterizm-contracts-tvm/blob/master/locklift.config.ts#L41).

Upon successful execution, the command will return a response similar to the following:

```bash
Added trusted address successfully

Target contract address: 0:d70fd67d3de5f447b35d79a9c51b9d721c45c9eabdf9cafdd894fa17425bea9f
Transfer hash: e32ee9f05ff5093ec031b831ccd60019f7d1b265f8052843cd5670ad41feb855
```

#### TON

```bash
npx blueprint run
    testnet
    {select your key}
    Chain ID: {trustedChainId}
    Trusted address (uint): {trustedAddress}
```

The command accepts the following parameters:

* **trustedChainId** - mandatory parameter: the ID of the network of the trusted address. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **trustedAddress** - mandatory parameter: the address of the trusted demo contract. You will be able to review the list of available external relays later on a dedicated page. Please note that this parameter accepts a **uint** value, not **address**. Therefore, you will need to convert the hexadecimal address to decimal

Upon successful execution, the command will return a response similar to the following:

```bash
Done!
```

#### Solana

```bash
npx ts-node scripts/settings/8-add-trusted-address.ts
    Trusted chain ID: {trustedChainId}
    Trusted address: {trustedAddress}
    Need to remove old trusted address in chain (0 - not removing, 1 - removing): {needToRemoveFlag}
    Solana Endpoint: {solanaEndpoint}
```

The command accepts the following parameters:

* **trustedChainId** - mandatory parameter: the ID of the network of the trusted address. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **trustedAddress** - mandatory parameter: the address of the trusted demo contract. You will be able to review the list of available external relays later on a dedicated page. Please note that this parameter accepts a **uint** value, not **address**. Therefore, you will need to convert the hexadecimal address to decimal
* **needToRemoveFlag** - flag indicating whether to delete the old trusted address of the specified network
* **solanaEndpoint** - solana rpc url

If successful, the command will not output anything. In case of an error, a log will be displayed.

## Sending cross-chain messages

To simplify the process of sending messages to the demo contract, console commands have also been developed.

#### EVM

{% code overflow="wrap" %}

```bash
npx hardhat demo:sendmessage {contractAddress} {destinationChainId} {message} --network {networkName}
```

{% endcode %}

The command accepts the following parameters:

* **contractAddress** - mandatory parameter: the address of the demo contract in the source network
* **destinationChainId** - mandatory parameter: the ID of the destination network. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **message** - mandatory parameter: the text that will be transmitted from the source network to the destination network
* **networkName** - mandatory parameter: the name of the source network. You can check the list of available networks [here](https://github.com/Asterizm-Protocol/asterizm-contracts-tvm/blob/master/locklift.config.ts#L41)

Upon successful execution, the command will return a response similar to the following:

```bash
Message sent successfully

Total gas limit: 90759
AsterizmDemo address: 0x50c7297E385afCC365deD9069a346694107442F0
Transaction hash: 0x0f9a07ddaa9915905d5f764d3b68f432e48f39056faa017e6b87c8514b2bfcb5
```

#### TVM

{% code overflow="wrap" %}

```bash
npx locklift run --script ./scripts/demo/demo_sendmessage_tast.ts --contractAddress {contractAddress} --destinationChainId {destinationChainId} --message {message} --network {networkName}
```

{% endcode %}

The command accepts the following parameters:

* **contractAddress** - mandatory parameter: the address of the demo contract in the source network
* **trustedChainId** - mandatory parameter: the ID of the destination network. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **message** - mandatory parameter: the text that will be transmitted from the source network to the destination network
* **networkName** - mandatory parameter: the name of the source network. You can check the list of available networks [here](https://github.com/Asterizm-Protocol/asterizm-contracts-tvm/blob/master/locklift.config.ts#L41)

Upon successful execution, the command will return a response similar to the following:

```bash
Message sent successfully

Target contract address: 0:d70fd67d3de5f447b35d79a9c51b9d721c45c9eabdf9cafdd894fa17425bea9f
Transfer hash: ba52f4de4b423692e67a361a271f1edd7384f60aaf5e06404a27f7df0257bfdc
```

#### TON

***Coming soon***

#### Solana

```bash
npx ts-node scripts/demo-value/1-value-init-send.ts 
    DST chain id: {dstChainId}
    Amount: {amount}
    SRC address: {srcAddress}
    DST address: {dstAddress}
    Solana Endpoint: {solanaEndpoint}
```

The command accepts the following parameters:

* **dstChainId** - mandatory parameter: destination chain ID. You can review the list of available networks on the corresponding pages ([Mainnet](/technical-reference/mainnet.md) or [Testnet](/technical-reference/testnet.md))
* **amount** - mandatory parameter: the value that will be sent to the destination network
* **srcAddress** - mandatory parameter: client sender address in source chain
* **dstAddress** - mandatory parameter: cilent contract address in destination chain
* **solanaEndpoint** - solana RPC URL

If successful, the command will not output anything. In case of an error, a log will be displayed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.asterizm.io/guides/getting-started/1.-deploy-your-smart-contracts/asterizmdemo-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
