LogoLogo
  • Entangle
    • Overview
    • Security Audits
  • Universal Interoperability Protocol
    • Overview
    • Architecture
      • Scalability and Network Stability
        • L2 Utility Blockchains
        • Transmitter Groups
      • Security and Consensus Mechanism
      • Finality
      • Execution Latency
      • Compatibility and Interoperability
    • Developer Guides
      • Getting Started
      • Solidity
        • Simple Abstract Messenger Example
        • Deploying Your Custom EVM Protocol
        • Bridging Tokens with UIP
        • Become an EVM Transmitter
      • Solana
        • Simple Abstract Messenger Example
        • Deploying Your Custom Solana Protocol
        • Become a Solana Transmitter
      • Calculate Cross-Chain Transaction Cost
      • Customizable Message Transmission Options
      • How to Debug Sent Messages
      • SDK Setup
      • Revenue Sharing for Transmitters
      • How to Become a Super Transmitter
    • Endpoints
  • Universal Data Feeds
    • Overview
    • Architecture
      • Data Delivery Methods
        • Pull Model
        • Push Model
      • Oracle Contract & User Interaction
    • Developer Guides
      • Custom Data Feeds
      • Fetch Data via Pull Model (PAYG)
        • EVM Smart Contracts
        • Solana Smart Contracts
      • Fetch Data via Pull Model (Subscriptions)
        • EVM Smart Contracts
        • Solana Smart Contracts
      • Fetch Data via Push Model
        • EVM Smart Contracts
        • Solana Smart Contracts
    • User Guides
      • Accessing Feeds
      • Subscribe to a Data Feed
      • Check Subscription
      • Manage Subscription
      • Renew Subscription
    • Data Endpoints
  • Universal Token Standard
    • Overview
    • Architecture
      • Fee Components
    • Developer Guides
      • Manual Deploy
        • Token Deployment Types
        • Create a Custom Token
        • Factory Blueprint Deployment
        • Examples
          • Initial Setup
          • UTS Connector
            • Mint & Burn Connector Scheme
            • Lock & Unlock Connector Scheme
            • Connector Over Native Currency
          • UTS Token
            • Simple Token
            • Token with Messages
      • Bridge SDK
      • Token Verification
      • Fees Calculation & Gas Estimation Logic
      • Estimations
    • User Guides
      • Launch Universal Token
      • Create a Liquidity Pool
      • Expand Existing Token
      • Transfer Liquidity to Connector
      • Bridging
    • Contract Addresses
  • Entangle Interoperable Blockchain
    • Overview
    • Architecture
    • Developer Guides
      • Set up a Validator Node
      • Delegating to Validators
      • Undelegating from Validators
      • Supported Accounts
  • More
    • Media Kit
    • FAQ
    • Report an Issue
    • Become a Partner
Powered by GitBook
On this page
  • Prerequisites
  • Environment Setup
  • Set the Program Address
  • Whitelist Configuration
  • Deploying Contracts
  • Building the TypeScript SDK
  • Registering the Extension
  • Sending and Receiving Messages
  • Sending Messages
  • Receiving Messages
  • Conclusion

Was this helpful?

Export as PDF
  1. Universal Interoperability Protocol
  2. Developer Guides
  3. Solana

Simple Abstract Messenger Example

PreviousSolanaNextDeploying Your Custom Solana Protocol

Last updated 22 days ago

Was this helpful?

If you have any questions or need assistance, please feel free to use our to connect with an expert on our team.

An effective implementation of blockchain interoperability is sending cross-chain messages. Traditionally, without UIP, this would be a challenging task. However, UIP makes this an easy and safe process. This guide walks you through deploying a simple dApp that utilizes UIP to send cross-chain text messages between and other networks.

For this guide, we won't need to worry about fees as we will deploy the smart contracts on devnet, which is the commonly used Solana testnet network.

Prerequisites

Before you begin, you'll need to ensure you're familiar with the concepts and have the tools we'll be using for this guide. If you're unsure about anything, we recommend reading more via the provided links.

  • The programming language.

  • The development environment.

  • The toolkit.

We will be using the following native token:

Click on the token to be taken to its public faucet and complete the steps to acquire the necessary funds in your wallet.

Environment Setup

To begin with, let's setup the working environment.

1

Clone the example project from GitHub.

git clone https://github.com/Entangle-Protocol/UIP-examples.git
2

Change your directory to the project folder.

cd UIP-examples/other/Messenger/Solana
3

Install the JS dependencies.

bun install

Set the Program Address

To deploy your own instance of the messenger, you need to generate a custom keypair for it and put it in target/deployfolder.

Run the below command to generate your keypair.

solana-keygen grind --starts-with mes:1 --ignore-case

It will generate a file called <your program address>.json, where <your program address> is the resulting public key. Move it to the target/deployfolder using the below command.

mv <your program address>.json target/deploy/messenger-keypair.json

Next, replace the program address in programs/messenger/src/lib.rs and Anchor.toml with the public key of the generated keypair.

Whitelist Configuration

The Solana Messenger example employs a whitelist to only allow messages from specific contracts. For messages to be accepted, you will need to specify all the contracts from other chains that you plan on communicating with.

First, put the addresses of the deployed EVM contracts in programs/messenger/src/addresses.rs. They have to be padded with 12 zero bytes, as the EVM addresses undergo encoding to bytes.

If you want to change the chains you want to send messages to or chains you want to receive messages from, make changes to programs/messenger/src/instructions/send_message.rs or programs/messenger/src/instructions/execute.rs accordingly.

Alternatively, you can redesign the contract to add the allowed origins and destinations dynamically.

Deploying Contracts

Build the Solana program by running the below command.

anchor build

If you are planning to deploy to mainnet, run the following command.

anchor build --features mainnet

After that, you can deploy your program by running the below command.

solana program deploy --url devnet \
  --upgrade-authority ~/.config/solana/id.json \
  --program-id target/deploy/messenger-keypair.json target/deploy/messenger.so

Building the TypeScript SDK

To run the client-side scripts, make sure to build the TypeScript SDK after compiling the program.

cp target/idl/messenger.json target/types/messenger.ts ts-sdk/src/idl/
bun run build:sdk

Registering the Extension

Now, you need to register the protocol extension. Extensions exist to let the UIP transmitters know how to interact with your program. In essence, they are WebAssembly executables that are shared by uploading to the IPFS network. Every Solana contract connected to UIP needs to register its extension to start receiving messages.

Run the command below to compile the messenger extension.

rustup target add wasm32-wasip1
cargo build --target wasm32-wasip1 --release -p messenger-extension

You can run the initialization script to set up the messenger config and to register the extension.

anchor run initialize --provider.cluster devnet -- \
  --extension <extension CID>

Sending and Receiving Messages

In this section, we'll take a look at sending and receiving messages.

Sending Messages

To send a message from the Solana contract to another chain, use the send-message script.

anchor run send-message --provider.cluster devnet -- \
  --times 1 \
  --dst-chain base-sepolia \
  --fee 100000 \
  --custom-gas-limit 300000 \
  --text "Hi from Solana"

Here, we are sending one message, choosing the destination to be Base Sepolia, paying 0.0001 SOL for fees, and setting the gas limit for execution on target chain to be 300k.

Receiving Messages

To display all the messages sent from a wallet, copy the command below, update the sender address with the EVM address and run it.

anchor run get-messages-by-sender --provider.cluster devnet -- <your sender wallet address>

Conclusion

In this guide we created a dApp utilising SOL contracts to facilitate in cross-chain text messaging.

The generated target/wasm32-wasip1/release/messenger_extension.wasm file needs to be uploaded to IPFS. It can be done using a service such as (it’s free). Upon uploading, copy the CID of the extension file.

contact form
Solana
Rust
Anchor
Bun
Solana SOL
Pinata