Cross-chain transactions

In this section, we'll introduce you to the Rayls Protocol through hands-on examples, guiding you on how to harness its capabilities for private communication and asset transfers.

You'll learn to send arbitrary messages and teleport ERC20 tokens across blockchains, showcasing the protocol's versatility and ease of use. These examples are designed to kickstart your journey, offering a clear path to integrating Rayls into your blockchain projects.

First, let's get started with the pre-requisites and installation. Then we will work through some examples.

Development pre-requisites

You should first be familiar with writing and deploying contracts to your desired blockchains. This involves understanding the specific smart contract language and the deployment process for those chains.

Let's create a new Hardhat project

To install it, you need to create an npm project by going to an empty folder, running npm init, and following its instructions. You can use another package manager, like yarn, but we recommend you use npm 7 or later, as it makes installing Hardhat plugins simpler.

Once your project is ready, you should run:

npm install --save-dev hardhat

And now you create a new Hardhat project by running:

npx hardhat init

And then select either "Create a JavaScript project" or "Create a TypeScript project".


Installation

The Rayls Protocol NPM package

To use Rayls SDK, you need to interact with Rayls specific contracts from the @rayls/contracts NPM package.

In your hardhat project, include the Rayls Protocol SDK package.

npm i @rayls/contracts

Once installed, you can use the contracts in the library by importing them.


Infinite possibilities...

The Rayls protocol is highly flexible, so we'll begin by giving you a brief overview of its capabilities. However, it's designed to be adaptable, allowing you to customize and extend it to suit your specific needs.

📘

You MUST have the Rayls Endpoint contract installed in your Rayls Privacy Node Ledger.

Usage

All Rayls contracts are abstract — you extend them in your own contract and pass the required infrastructure addresses to the parent constructor. The three addresses are provided by the Privacy Node operator at deployment time:

  • _endpoint — the Privacy Node endpoint (handles cross-chain routing)
  • _raylsNodeEndpoint — the Privacy Node's bridge to the Rayls Public Chain
  • _userGovernance — the RBAC contract that manages user roles and permissions within the Privacy Node

Example — custom cross-chain app:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {RaylsApp} from "@rayls/contracts/RaylsApp.sol";

contract HelloWorldContract is RaylsApp {
    constructor(
        address _endpoint,
        address _raylsNodeEndpoint,
        address _userGovernance
    ) RaylsApp(_endpoint, _raylsNodeEndpoint, _userGovernance) {}
}

Example — ERC20 token:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {RaylsErc20Handler} from "@rayls/contracts/tokens/RaylsErc20Handler.sol";

contract MyToken is RaylsErc20Handler {
    constructor(
        string memory _name,
        string memory _symbol,
        address _endpoint,
        address _raylsNodeEndpoint,
        address _userGovernance,
        address _owner
    ) RaylsErc20Handler(_name, _symbol, _endpoint, _raylsNodeEndpoint, _userGovernance, _owner, false) {}
}

Usage

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {RaylsApp} from "@rayls/contracts/RaylsApp.sol";

contract HelloWorldContract is RaylsApp {
    constructor(
        address _endpoint
    ) RaylsApp(_endpoint, msg.sender) {}
}