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 Base-Sepolia Testnet using a storage contract. Specifically, the deposit
method will be called on Sepolia, passing the details of the function to be called on a smart contract deployed on Base-Sepolia (0x4bE595ab5A070663B314970Fc10C049BBA0ad489). The method will encode an address and an arbitrary number 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)
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
- 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/
- Install dependencies
Install the project dependencies by running:
yarn install
- Build the SDK
Build the SDK by running the following command:
yarn build
- 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-generic-message-transfer
folder within examples:
cd examples/evm-to-evm-generic-message-transfer
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-message-transfer
and run:
cd examples/evm-to-evm-generic-message-transfer
yarn run transfer
The example will use ethers
in conjunction with the sygma-sdk to call a function on a smart contract on Base-Sepolia 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.