LogoLogo
  • Guide to Developing on Layer One X
    • Contents
    • L1X vs. Other Chains
    • L1X Technology Overview
      • X-Talk Overview
      • L1X System Architecture
      • XTalk Deep Dive
  • L1X Documentation
    • Setup L1X Development Environment
  • Use Cases
    • Use Case 1: Decentralised Finance (DeFi)
      • Key Components and Protocols
      • Use Case Implementation Examples
      • Future Trends and Innovations
    • Use Case 2: Non-Fungible Tokens (NFTs)
      • Applications in Art, Gaming, and Collectibles
      • Use Case Examples and Case Studies
      • Emerging Trends in NFTs
    • Use Case 3: Identity Management
      • Importance of Self-Sovereign Identity
      • Use Cases in Identity Verification and Authentication
      • Projects and Initiatives in Identity Management
      • Privacy and Security Considerations
    • Use Case 4: Content Monetisation
      • Challenges in Content Monetisation
      • Blockchain Solutions for Micropayments and Royalties
      • Use Case Examples in Publishing, Music, and Media
      • Future Opportunities and Trends
    • Use Case 5: Voting and Governance
      • Advantages of Blockchain in Voting Systems
      • Use Cases in Elections, Polls, and Governance
      • Projects and Platforms for Decentralised Voting
      • Challenges and Considerations
    • Use Case 6: Decentralised Storage
      • Problems with Centralised Storage Solutions
      • Use Cases in Decentralised File Storage
      • Projects and Platforms for Decentralised Storage
      • Scalability and Performance Challenges
    • Use Case 7: Gaming and Virtual Worlds
      • Introduction to Blockchain Gaming
      • Use Cases in Virtual Economies, Assets, and Ownership
      • Notable Projects and Success Stories
      • Trends and Innovations in Blockchain Gaming
    • Use Case 8: Healthcare and Medical Records
      • Importance of Data Integrity and Security in Healthcare
      • Use Cases in Medical Records Management
      • Projects and Initiatives in Health Data Management
      • Regulatory Compliance and Privacy Concerns
    • Use Case 9: Decentralised Autonomous Organisations (DAOs)
      • Understanding DAOs
      • Use Cases in Governance, Funding, and Decision Making
      • Future Developments
    • Use Case 10: Supply Chain Management
      • Overview of Supply Chain Challenges
      • Blockchain Solutions in Supply Chain
      • Use Case Examples in Tracking and Traceability
      • Potential Benefits and Challenges
  • Get Started with L1X SDE
    • L1X Workspace Overview
      • L1X SDE toolkit architecture
    • Development Workspace Environment & Contract Types
      • 1 - Contemporary Contracts
      • 2 - ERC20 Contract Deployment and Cross Contract Call
      • 3 - X-Talk Flow Cross Chain Contract
      • 4 - Balancer-v2
  • Build with Developer Playground
    • Developer Playground Resource
  • Core Concepts
    • Account
    • Address
    • Transaction
    • Smart Contract
    • Contract Lifecycle (VM)
    • Cross-Contract call
      • L1X VM Cross-Contract Calls
      • L1X VM-EVM Cross Contract Calls
    • Cluster
Powered by GitBook
On this page
  • Getting to Know the X-Talk Cross-Chain Swap Demo Template:
  • Step 1: Setting Up Your Environment
  • Step 2: Download the Demo Template
  • Step 3: Starting with Workspace Workflow Script Commands
  • Step 4: Building Smart Contracts
  • Step 5: Setting Up Local Development Network Services
  • Step 6: Deploying and Creating an Instance From a Compiled Contract
  • Section 7: Updating Configuration for Event Listener Monitoring Service via the source_registry.o Contract
  • Section 8: Starting L1X L2 Monitoring Services
  • Section 9: Starting the ERC20 Token Swap
  1. Get Started with L1X SDE
  2. Development Workspace Environment & Contract Types

3 - X-Talk Flow Cross Chain Contract

Previous2 - ERC20 Contract Deployment and Cross Contract CallNext4 - Balancer-v2

Last updated 1 year ago

This guide will walk you through the basics of a demo template that simplifies cross-chain swaps.

You can find the contract's code in the l1x-contracts directory, shown below:

exa -T -L 1 ./l1x-contracts
	./l1x-contracts
	├── source_registry
	└── xtalk_swap_flow

The purpose of this demo template is to make cross-chain swaps less complicated for you. We will explain how it works in a step-by-step manner. Let's dive in!

  • 1.1. Create an empty folder for this demonstration:

     $ mkdir -p $HOME/l1x-home/l1x-demo-home/
  • 1.2. Change your current directory to the newly created folder:

    $ cd $HOME/l1x-home/l1x-demo-home/

  • 2.2. Use the l1x-forge command to create a new project workspace. We'll name it l1x_demo03_cross_chain_swap and use the template l1x-cross-chain-swap:

    $ l1x-forge new --name l1x_demo03_cross_chain_swap --template l1x-cross-chain-swap
  • 2.3. After running the command, you'll receive a confirmation message indicating the successful creation of the "l1x_demo02_erc20_cross_call" contract:

    Created contract l1x_demo03_cross_chain_swap
  • 2.4. Your workspace will now be populated with content from the template.

     	$ exa -T -L 1 ./l1x_demo03_cross_chain_swap
     		./l1x_demo03_cross_chain_swap
     		├── Cargo.lock
     		├── Cargo.toml
     		├── devbox-services-devnode.log
     		├── devbox.json
     		├── devbox.lock
     		├── devnet-services-dc.yml
     		├── l1x-conf
     		├── l1x-contracts
     		├── process-compose-devnode.yaml
     		├── README.md
     		├── rust-toolchain.toml
     		└── rustfmt.toml

  • 3.1. Introduction to Devbox Shell and Workflow Commands

    If you're new to the l1x-sde template workspace, it's a good idea to familiarize yourself with the basics of the devbox shell and workflow commands. This will help you get started more smoothly. You can review the following links for an overview:

  • 3.2. Default Commands to Begin With

    To start using the workspace, there are some default commands you can use:

    • Activate the Shell: To access the devbox shell, simply enter the following command in your terminal:

    $ devbox shell
    • List Default Commands: To see a list of the built-in default commands available in the devbox shell, you can use the following command:

      	(devbox)$ devbox run -l | sort
      	* 01_init_setup
      	* 01_teardown_setup
      	* 02_check_chain_state
      	* 02_check_devnet_db_state
      	* 02_prune_devnode
      	* 02_start_devnode
      	* 02_stop_devnode
      	* 03_00_start_monitor_services_cmd
      	* 03_01_start_monitor_services_leader
      	* 03_02_start_monitor_services_regular1
      	* 03_03_start_monitor_services_regular2
      	* 03_04_stop_monitor_services
      	* 04_01_start_monitor_signer_node
      	* 10_00_compile_ebpf_cmd
      	* 10_01_compile_ebpf
      	* 11_clean_logs
      	* 11_clean_objs
      	* 18_cli_ro_call_cmd
      	* 18_cli_ro_get_sources_from_registry
      	* 18_cli_sub_txn_register_source_registry
      	* 40_cli_deploy_ebpf
      	* 40_cli_deploy_ebpf_cmd
      	* 41_cli_init_ebpf
      	* 41_cli_init_ebpf_cmd
      	* 60_forge_install_ebpf_cmd_force_deploy
      	* 61_forge_install_ebpf_cmd_reuse_deploy
      	* 80_00_forge_install_ebpf_all
      	* 80_01_forge_install_ebpf_source_registry
      	* 80_02_forge_install_ebpf_xtalk_swap_flow
      	Available scripts:
  • Initialize the Workspace: To prepare your workspace for building and testing, run:

     (devbox)$ devbox run 01_init_setup

Now you have all the necessary tools and packages to work with the demo template workspace.

Now, let's guide you through the process of building the smart contracts.

  • 4.1 Compiling the Contract for l1x-vm

To compile the l1x_evm_cross_contract contract, simply use this command:

(devbox)$ devbox run 10_01_compile_ebpf

Running this command will compile the contract for you and save the compiled files in the ./l1x-artifacts folder automatically.

After executing the command, you'll discover the following files in the ./l1x-artifacts folder:

```shell
	exa -T -L 1 ./l1x-artifacts
		./l1x-artifacts
		├── source_registry.base64
		├── source_registry.ll
		├── source_registry.o
		├── source_registry.versioned.ll
		├── source_registry.wasm
		├── xtalk_swap_flow.base64
		├── xtalk_swap_flow.ll
		├── xtalk_swap_flow.o
		├── xtalk_swap_flow.versioned.ll
		└── xtalk_swap_flow.wasm
```

That's it! We've successfully completed the steps for building smart contracts.

In this step, we will walk you through the process of configuring local development l1x-chain network.

  • 5.1 Choose the Chain Type: To begin, select the "L1X_CFG_CHAIN_TYPE": "local_devnet" option. Next, open a new terminal and activate the devbox shell:

    $ devbox shell
  • 5.2 Start the Devnode Services: While in the devbox shell, run the following command:

    (devbox)$ devbox run 02_start_devnode
  • 5.3 Wait for Services to Initialize: After executing the previous command, please wait for approximately 160 seconds. During this time, the services will start up and become operational. You will also observe the L1X node beginning to produce blocks.

  • 5.4 Verify DevNet Service Status: To ensure that everything is running smoothly, use the following command to check the service status:

    (devbox)$ devbox run 02_check_chain_state
    (devbox)$ devbox run 02_check_devnet_db_state
  • 5.5 Troubleshooting: Occasionally, we might encounter a problem where the l1x-node-client server and the cassandra DB service do not sync properly, as indicated by the state shown in the image below.

  • To fix this issue and get your setup back on track, follow these simple steps:

    (devbox)$ devbox run 02_stop_devnode
    (devbox)$ devbox run 02_prune_devnode
    (devbox)$ devbox run 02_start_devnode

These commands will help reset and restart the necessary components. Your setup should work smoothly after completing these steps.

  • 6.1: Deploying and Creating a Contract Instance for source_registry.o and xtalk_swap_flow.o on l1x-vm

    To deploy and create a contract instance for source_registry.o and xtalk_swap_flow.o on l1x-vm, you can use the following command:

    (devbox)$ devbox run 80_00_forge_install_ebpf_all
  • 6.2: Understanding Traces

    When deploying and creating contract instances, it's important to note the following information from traces, will be helpful for debugging:

    • The payload used for deploying and the deployed address for the source_registry.o contract.

    • The payload used for creating an instance and the instance address for the source_registry.o contract.

  • The payload used for deploying and the deployed address for the xtalk_swap_flow.o contract.

  • The payload used for creating an instance and the instance address for the xtalk_swap_flow.o contract.

  • 6.3: Contract Address Registry

The addresses for deployed contracts and their instances are automatically updated in the configuration file l1x-conf/config-contract-address-registry.yaml. This registry keeps track of contract addresses.

  • 6.4: Updating JSON Payload with New Instance Addresses

Update the following JSON payload with new instance addresses, before proceeding:

```shell
l1x-conf/scripts/012-01-uc-event-registry-register-new-source.json
l1x-conf/scripts/012-02-uc-event-registry-get-source-from.json
```
  • 7.1: Updating the source_registry.o Contract:

  1. Update the configuration file for the payload.

The Source Registry has to be updated about information of external Source chain. In this demonstration, it is the Liquidity pool contract deployed on the Ethereum chain at the address `0xDa4140B906044aCFb1aF3b34C94A2803D90e96aA`, along with the instance address of `xtalk_swap_flow.o` and the events to be filtered. This information gets used by L2 layer Event Listener monitoring services.

To make this update, manually edit the payload file located at `l1x-conf/scripts/012-01-uc-event-registry-register-new-source.json`.
  1. Run the following command to execute the transaction:

(devbox)$ devbox run 18_cli_sub_txn_register_source_registry

Check the trace log for the following information, which indicates that the transaction has been successfully executed:

  1. Run the following command to confirm the updates to the source registry transaction status:

```shell
(devbox)$ devbox run 18_cli_ro_get_sources_from_registry
```

To start L1X L2 monitoring services, follow each steps in a new devbox shell terminal:

  • 8.1: Start the Event Listener "Leader" Service:

     (devbox)$ devbox run 18_cli_ro_get_sources_from_registry
  • 8.2: Start the Event Listener "Regular" Service:

     (devbox)$ devbox run 03_02_start_monitor_services_regular1
  • 8.3: Understanding Traces:

The trace prints show that the Leader node has discovered peers and begun fetching new blocks from the source Ethereum chain.

  • 8.4: Launch the Signer Node Service:

     (devbox)$ devbox run 04_01_start_monitor_signer_node

The trace prints show that the Signer node has started fetching new blocks from the L1X L1 layer.

To start the ERC20 Token Swap, follow these steps:

  • 9.1: Get Some Test Tokens for Your Wallet

Request some test tokens for your Metamask wallet from the L1X team.

  • 9.2: Start the Token Swap on the Source Liquidity Pool Contract

Here's how you can do it:

  • Make sure you are on the correct page before proceeding with the InitiateSwap transaction.

  • Connect your web3 wallet (we recommend using MetaMask) and select the account that has the test tokens from the L1X team.

  • Execute the InitiateSwap transaction. In this demonstration, use the following arguments when making the InitiateSwap transaction call:

Sender Address: 0x4603e703309Cd6C0b8bada1e724312242ef36ECb
Amount: 100
Network: optimism
Receiver Address: 0x853f409f60D477b5e4ECdfF2f2094D4670AFA0A1
Amount: 100
Destination Address: 0xc31beb2a223435a38141Ee15C157672A9fA2997D

  • Wait for the InitiateSwap transaction to complete.

  • 9.3: Confirm the Swap

To confirm the swap, follow these steps:

  • Find the transaction hash for the swap executed on the Destination Liquidity Pool deployed in Optimism Goerli Testnet. You can locate this in the transaction receipt, which is available in the trace prints of the Signer Node monitoring service.

  • Open the contract at the address 0x44436a43330122a61a4877e51ba54084d5bd0ac6 and verify that the tokens have been successfully transferred to the destination address.

Congratulations! You've successfully completed the ERC20 Token Swap process. We hope this guide has been helpful in getting you through it smoothly. If you have any questions or run into any issues, feel free to reach out to our L1X team for assistance. Happy swapping!

2.1. Make sure you can access the l1x-forge tool from your command line. If you don't have l1x-forge installed, follow the instructions in before proceeding.

Go to the and search for the LP contract at this address: 0xDa4140B906044aCFb1aF3b34C94A2803D90e96aA

Visit and search for this transaction hash to confirm that your swap was successful.

Step 2: Checking the L1X Tool
Step 3: Starting with Workspace Workflow Script Commands
Step 4: Understanding Configuration Files and Default Settings
Step 5: Getting Started with the Devbox Shell
Step 4: Building Smart Contracts
Step 5: Setting Up Local Development Network Services
Step 6: Deploying and Creating an Instance From a Compiled Contract
Section 7: Updating Configuration for Event Listener Monitoring Service via the source_registry.o Contract
Section 8: Starting L1X L2 Monitoring Services
Section 9: Starting the ERC20 Token Swap
Goerli Testnet Explorer
Goerli Optimism Testnet Explorer
Getting to Know the X-Talk Cross-Chain Swap Demo Template:
Step 1: Setting Up Your Environment
Step 2: Download the Demo Template