Cross-chain transactions
This section introduces the Rayls Protocol through hands-on examples, showing how to use it for private communication and asset transfers.
You will learn to send arbitrary messages and teleport ERC20 tokens across blockchains, which gives a working sense of what the protocol can do and how quickly it can be picked up. The examples are there to get you moving, and they set out a clear path to integrating Rayls into your own blockchain projects.
Start with the prerequisites and the installation, then work through the examples.
Development pre-requisites
You should already be comfortable writing and deploying contracts to your chosen blockchains, which means knowing the smart contract language and the deployment process for those chains.
Let's create a new Hardhat project
To install Hardhat, create an npm project by going to an empty folder, running npm init, and following the instructions. Another package manager such as yarn will work, although npm 7 or later is recommended because it makes installing Hardhat plugins simpler.
Once your project is ready, you should run:
npm install --save-dev hardhatAnd now you create a new Hardhat project by running:
npx hardhat initAnd then select either "Create a JavaScript project" or "Create a TypeScript project".
Installation
The Rayls Protocol NPM package
To use the 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/contractsOnce installed, you can use the contracts in the library by importing them.
Infinite possibilities...
The Rayls protocol is flexible by design, so what follows is a brief overview of its capabilities rather than an exhaustive list, and it can be customised and extended to suit your specific needs.
📘### You MUST have the Rayls Endpoint contract installed in your Rayls Sovereign ledger.
Usage
All Rayls contracts are abstract, so you extend them in your own contract and pass the required infrastructure addresses to the parent constructor. The three addresses are provided by the Rayls Sovereign operator at deployment time:
_endpoint, the endpoint in the Rayls Sovereign ledger, which handles cross-chain routing_raylsNodeEndpoint, the bridge from the Rayls Sovereign ledger to the Rayls Public Chain_userGovernance, the RBAC contract that manages user roles and permissions within the Rayls Sovereign ledger
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.24;
import {RaylsApp} from "@rayls/contracts/RaylsApp.sol";
contract HelloWorldContract is RaylsApp {
constructor(
address _endpoint,
address _raylsNodeEndpoint,
address _userGovernance
) RaylsApp(_endpoint, _raylsNodeEndpoint, _userGovernance) {}
}Updated 18 days ago
