Skip to main content

GMP Example With A Simple Storage Contract

GMP Example With A Simple Storage Contract

In the following example, we will use the TESTNET environment to pass a generic message from Ethereum Sepolia to Cronos Testnet using a simple storage contract. Specifically, the deposit method will be called on Sepolia, passing the details of the function to be called (the store function, or function signature 0xa271ced2) on a smart contract deployed on Cronos (0xcb9eb2b2abbd51945a82f77e789c26720b3835bf). The method will encode the current UNIX timestamp as the payload to be passed and stored in the destination chain contract. The data can be read by calling the retrieve function on the destination chain contract by querying the depositor address derived from the private key.

This is an example script that demonstrates the functionality of the Sygma SDK and the wider Sygma ecosystem of relayers and bridge and handler contracts. The complete example can be found in this repo.

Prerequisites

Before running the script, ensure that you have the following:

  • Node.js v18
  • Yarn (version 3.4.1 or higher)
  • A development wallet funded with Sepolia ETH for gas
  • The exported private key of your development wallet
  • An Ethereum provider (in case the hardcoded RPC within the script does not work)
danger

We make use of the dotenv module to manage exported private keys with environment variables. Please note that accidentally committing a .env file containing private keys to a wallet with real funds, onto GitHub, could result in the complete loss of your funds. Never expose your private keys.

Getting Started

  1. Clone the repository

Clone the sygma-sdk repository into a directory of your choice, and then cd into the folder:

git clone git@github.com:sygmaprotocol/sygma-sdk.git
cd sygma-sdk/
  1. Install dependencies

Install the project dependencies by running:

yarn install
  1. Build the SDK

Build the SDK by running the following command:

yarn sdk:build
  1. Usage

This example uses the dotenv module to manage private keys. To run the example, you will need to configure your environment variable to include your test development account's exported private key. A .env.sample is provided as a template.

DO NOT COMMIT PRIVATE KEYS WITH REAL FUNDS TO GITHUB. DOING SO COULD RESULT IN COMPLETE LOSS OF YOUR FUNDS.

Create a .env file in the evm-to-evm GMP example folder:

cd examples/evm-to-evm-generic-mesage-passing
touch .env

Replace between the quotation marks your exported private key:

PRIVATE_KEY="YOUR_PRIVATE_KEY_HERE"

To call the function on the destination chain contract, cd into the example folder examples/evm-to-evm-generic-mesage-passing and run:

cd examples/evm-to-evm-generic-mesage-passing
yarn run transfer

The example will use ethers in conjunction with the sygma-sdk to call a function on a smart contract on Cronos by calling the Deposit method on Sepolia and passing the details of the function to be called.

Replace the placeholder values in the .env file with your own Ethereum wallet private key and provider URL.