Skip to main content

Multichain Relayer and Gas Station example

In this article you'll learn how to run end-to-end tests on the entire Multichain Relayer system.

Required tools

For this tutorial, you'll need to have installed:


Before you start testing, set up your local environment and install the Relayer server, the Event indexer and NEAR CLI.

Alpha stage

The Multichain Relayer solution is currently under development. Users who want to test-drive this solution should keep in mind that the product is in alpha stage, and a code audit is pending.

Multichain Relayer server

The main function of this server is interfacing with foreign chain RPCs sending both pre-signed funding transactions to cover gas and the actual pre-signed transaction once the funding is done.

To run the Multichain Relayer Server:

  1. Configure the Multichain Relayer by editing the config.toml file
  2. Start the multichain relayer server:
    cargo run

Find the Multichain Relayer server source code in this GitHub repository.

Gas Station Event indexer

The event indexer picks up events emitted from the gas station contract used for generating signed foreign chain transactions and calls the multichain relayer /send_funding_and_user_signed_txns endpoint locally.

To run the Gas Station indexer:

  1. Ensure you have the Multichain Relayer Server running on localhost:3030

  2. Create and activate a Python virtual environment:

    pip install requirements.txt
  3. Update the config.toml configuration file with appropriate values

    network = "testnet"
    # gas station contract account id
    contract_id = "canhazgas.testnet"
  4. Run the indexer:


Find the Gas Station Event indexer source code in this GitHub repository.

Running tests

The gas station contract supports EIP-1559 transactions.

  1. Set the transaction details of the EVM transaction you want to send in, run the script, and save the RLP hex string output.

Python and Rust output different hex RLP encoded transactions.

  1. Ensure the Multichain Relayer server is configured correctly and running.

  2. Ensure the Gas Station indexer is running locally.

  3. Construct the signed transaction using the near-cli-rs. The receiver account ID should be the gas station contract. You will need 2 actions if you want the gas station to cover your gas cost on the foreign chain:

    • 1 action to send the NEAR equivalent
    • 1 function call to the gas station.

    You should transfer the amount of NEAR that's needed to cover gas both on NEAR and on the foreign chain. You also need to paste in the RLP generated hex for the EVM transaction you want on the other chain generated in step 1.

    When it asks you to send or display, choose send. Example below:

    near contract call-function as-transaction canhazgas.testnet create_transaction json-args '{"transaction_rlp_hex":"eb80851bf08eb000825208947b965bdb7f0464843572eb2b8c17bdf27b720b14872386f26fc1000080808080","use_paymaster":true}' prepaid-gas '100.000 TeraGas' attached-deposit '0.5 NEAR' sign-as nomnomnom.testnet network-config testnet sign-with-keychain send
  4. Get the "id" from the receipts from the call in step 4, and use that to call sign_next twice:

     near contract call-function as-transaction canhazgas.testnet sign_next json-args '{"id":"16"}' prepaid-gas '300.0 Tgas' attached-deposit '0 NEAR' sign-as nomnomnom.testnet network-config testnet sign-with-keychain send

Options for testing purposes

Instead of creating a signed transaction and calling the gas station contract to sign it, you can get the recently signed transactions by calling the contract while replacing the blockheight with a more recent block height:

near contract call-function as-read-only canhazgas.testnet list_signed_transaction_sequences_after json-args '{"block_height":"157111000"}' network-config testnet now

This will return something like the output below. Take an individual entry in the list of JSONs and send that as the payload of a POST request to the /send_funding_and_user_signed_txns endpoint:

"created_by_account_id": "b807806adcb73f6aecb5ed98bb8bd7bbe7bbf8ed342596ab700ef6b050abc4c3",
"foreign_chain_id": "97",
"signed_transactions": [
"created_by_account_id": "b807806adcb73f6aecb5ed98bb8bd7bbe7bbf8ed342596ab700ef6b050abc4c3",
"foreign_chain_id": "97",
"signed_transactions": [
Was this page helpful?