Build your first XCDP - Solana to EVM Contract and XCDP - EVM to Solana Contract
Step by Step guide with detailed process. In this guide we will use Solana devnet, Sepolia and L1X TestNet to deploy X-Talk Flow Contract.
Building Blocks for XCDP
Smart Contracts on Solana that will be the endpoints for sending and receiving messages. This is runtime agnostic.
X-Talk XCDP Solana-EVM Flow Contract Deployment and Initialisation to facilitate programmability while sending and receiving messages.
X-Talk XCDP EVM-Solana Flow Contract Deployment and Initialisation to facilitate programmability while sending and receiving messages.
Smart Contracts on EVM-compatible chain (Sepolia in this example) that will be the endpoints for sending and receiving messages. This is runtime agnostic.
XCDP Process
This page is divided into 4 parts, for the ease of understanding, as listed below
Basic Steps: Common for both Solana-EVM and EVM-Solana
Solana to EVM Integration
EVM to Solana Integration
X-Talk Gateway Contract Address
I. Basic Steps
This section is categorised into Pre-Requisites, Set up Solana Project and Set up Sepolia Project.
Step 1: Pre-Requisites
Ensure Pre-Requisites for Solana and L1X are installed.
Step 2: Set up Solana Project
Open a new terminal to create Solana project
Step 1: Initialize a New Project
Create a New Directory
Initialize a New Anchor Project
Step 2: Write your Solana smart contract
Paste your contract code at /programs/flow_contract/src/lib.rs
Step 3: Update Cargo.toml
Ensure that you update at programs/flow_contract/Cargo.toml
Step 4: Install Dependencies
Goto solana-project-name/flow_contract and then run below commands
Step 5: Compile the Smart Contract
Step 6: Display the list of Key Pairs
Output is YOUR_SOLANA_PROGRAM_ID. Save it as it is used later at various instances.
Step 7: Declare PROGRAM_ID
Goto program/flow_contract/src/lib.rs and update declare_id! with YOUR_SOLANA_PROGRAM_ID.
Below is the snapshot for your reference
Step 8: Configure Scripts
Create scripts folder and add below scripts to it.
Script to Initiate Contract
Ensure that the connection is set to devnet
Load the wallet keypair path (for the file id.json) as YOUR_KEYPAIR_PATH
Update programId with YOUR_SOLANA_PROGRAM_ID
Update idlString with YOUR_IDL_PATH (the path to /target/idl/flow_contract.json)
Configure Anchor.toml
Update flow with YOUR_SOLANA_PROGRAM_ID
Update wallet with YOUR_KEYPAIR_PATH
Set path for initiate_flow.ts script
Step 9: Compile, Deploy and Run Solana Program
Compile the Solana Program
Deploy the Solana Program
Run the Solana Program
Output contains YOUR_SOLANA_DATA_ACCOUNT and YOUR_SOLANA_TRANSACTION_HASH
Save it as it is used later.
Step 3: Set up EVM Project
You can use Hardhat to compile, deploy and interact with evm contracts. Note, this example is on Sepolia.
Step 1: Initialize a New Project
Create a New Directory (if you're starting fresh):
Initialize a new NPM project:
Step 2: Install Hardhat and Set Up the Project
Install Hardhat:
Set up the Hardhat project: Run the setup command and choose to create a JavaScript project:
When prompted, select to create a JavaScript project. Follow the prompts to add a
.gitignoreand install the project's dependencies.
Step 3: Install Necessary Plugins and Dependencies
Install the Hardhat Toolbox plugin
Step 4: Write your EVM Smart Contract
Create your smart contract file as contracts/XCDPCore.sol
Step 5: Scripts and Configuration Settings
Write deployment scripts or tests as needed, using the setup you've created. Example Provided below.
Sample Hardhat Configuration file
Step 6: Contract Deployment
Output you get YOUR_EVM_CONTRACT_ADDRESS. Save it for now.
II. Solana to EVM Integration
This section is dedicated to send a message from Solana to any EVM-compatible chain, Sepolia in this example.
Step 1: Implementing L1X X-Talk Solana-EVM Flow Contract
Flow Contracts are at the core of cross-chain application development. They enable logic programmability, reducing integration and maintenance overhead and enable scalability.
Create a new L1X project that provides the necessary files to get started
Use the provided code below to implement the cross-chain xcdp Solana to EVM logic.
Create your L1X XCDP Solana-EVM Flow Contact at src/lib.rs
The Fundamental Building Blocks of X-Talk require the below building blocks in X-Talk Contract.
Data Structures: Define messages and events used within the contract.
Event Handling: Parse, log, and handle blockchain events.
State Management: Load and save the contract's state to maintain event records.
Message Parsing: Convert blockchain event logs into usable data formats.
Event Emission and Logging: Emit structured logs for cross-chain messaging.
Security: Ensure that only valid and expected data is processed.
Ensure you have all the necessary packages, libraries and dependencies in your Cargo.toml file as below.
To deploy the X-Talk flow contract, you can use this command on your project level. After successfully building, you will find the "project_name.o" file in target/l1x/release folder. This is the object file which will be deployed.
To deploy your contract, use an existing L1X Account on TestNet.
Create Wallet
Create your own wallet to generate a new keypair.
Import Wallet
Import you existing wallet using the l1x-cli-beta tool, by providing a private key. If you don't have one, Create Wallet.
Default Wallet
After Importing your wallet set it to be the default interaction account.
-- Check Endpoints in Interface Essentials for TestNet Faucet
Deploy your X-Talk Contract with l1x-cli-beta
Response expected:
To initiate your smart contract, use this command:
Response expected:
The instance address is your contract address which you can use to call your functions and interact.
Step 2: Register Solana Contract and X-Talk Solana-EVM Flow Contract with X-Talk Node
X-Talk Nodes allow for data listening and send to the X-Talk Solana-EVM Flow contract.
To register your addresses to the source registry, you need to call this:
Request Example:
Step 3: Implementing Script to Emit Event from Solana to EVM
Step 1: Add Script to Emit Events
In your solana project, inside scripts folder add emit_event.ts script.
Update walletKeypair with YOUR_KEYPAIR_PATH
emitEvent() arguments are in the sequence: message, destinationNetwork and destinationAddress.
message is set to "Hello world!". You can send the message you want.
destinationNetwork is set to "sepolia". (Update your EVM-compatible destination network here.)
Update destinationAddress with YOUR_EVM_CONTRACT_ADDRESS
Step 2: Update script path in Anchor.toml
Add the path for emit_event.ts script in Anchor.toml
Step 4: Send Message from Solana to EVM
To verify that event is received at YOUR_EVM_CONTRACT_ADDRESS, goto EVM blockchain explorer, check for the transaction with X-Talk Gateway for Sepolia mentioned in the table.
III. EVM to Solana Integration
This section is dedicated to send a message from any EVM-compatible chain (Sepolia in this example) to Solana.
Step 1: Implementing L1X X-Talk EVM-Solana Flow Contract
Flow Contracts are at the core of cross-chain application development.
Create a new L1X project that provides the necessary files to get started
Use the provided code below to implement the EVM to Solana cross-chain logic.
Create your L1X XCDP EVM-Solana Flow Contact at src/lib.rs
The Fundamental Building Blocks of X-Talk require the below building blocks in X-Talk Contract.
Data Structures: Define messages and events used within the contract.
Event Handling: Parse, log, and handle blockchain events.
State Management: Load and save the contract's state to maintain event records.
Message Parsing: Convert blockchain event logs into usable data formats.
Event Emission and Logging: Emit structured logs for cross-chain messaging.
Security: Ensure that only valid and expected data is processed.
Ensure you have all the necessary packages, libraries and dependencies in your Cargo.toml file as below.
To deploy the X-Talk flow contract, you can use this command on your project level. After successfully building, you will find the "project_name.o" file in target/l1x/release folder. This is the object file which will be deployed.
To deploy your contract, use an existing L1X Account with L1X for Mainnet and L1X TestNet for TestNet.
Create Wallet
Create your own wallet to generate a new keypair.
Import Wallet
Import you existing wallet using the l1x-cli-beta tool, by providing a private key. If you don't have one, Create Wallet.
Default Wallet
After Importing your wallet set it to be the default interaction account.
-- Check Endpoints in Interface Essentials for TestNet Faucet
Deploy your X-Talk Contract with l1x-cli-beta
Response expected:
To initiate your smart contract, use this command:
Response expected:
The instance address is your contract address which you can use to call your functions and interact.
Step 2: Register Sepolia Contract and X-Talk EVM-Solana Flow Contract with X-Talk Node
X-Talk Nodes allow for data listening and send to the X-Talk EVM-Solana Flow contract.
To register your addresses to the source registry, you need to call this:
Request Example:
Step 3: Implementing Script to Emit Event from EVM to Solana
Step 1: Add Script to Emit Events
In your EVM project, inside scripts folder add emit_event.js script.
Update XCDPContractAddress with YOUR_EVM_CONTRACT_ADDRESS
_l1xSend() arguments are in the sequence: message, destinationNetwork and destinationAddress.
message is set to "Hello from L1X!". You can send the message you want.
destinationNetwork is set to "Solana".
Update destinationAddress with Solana Program ID concatenated with Solana Data Account i.e. YOUR_SOLANA_PROGRAM_ID_YOUR_SOLANA_DATA_ACCOUNT
Step 4: Send Message from Sepolia to Solana
To verify that event is received at YOUR_SOLANA_PROGRAM_ID, go to Solana explorer, check for the transaction with X-Talk Gateway for Solana mentioned in the table.
IV. X-Talk Gateway Contract Address
Below table contains a list of contract address that serve as an authenticated entry to interact with X-Talk from respective client chain network.
Sepolia
0xf650162aF059734523E4Be23Ec5bAB9a5b878f57
SOLANA (Devnet)
GsU9N7gPtkMCSMwcEsyvj4sHcdoptHRyVwstbKiKmXeU
Last updated