Polygon To Ramestta
In order to natively read Polygon data from the Ramestta EVM chain, the mechanism utilized is known as 'State Sync'. This process facilitates the transfer of arbitrary data from the Polygon chain to the Ramestta chain. The essential steps involved include validators on the Heimdall layer listening for a specific event called 'StateSynced' from a Sender contract. Once this event is detected, the associated data is written to the Receiver contract. More details about this mechanism can be found here.
To enable this functionality, it is imperative to map the Sender and Receiver contracts on Polygon. The StateSender.sol contract must be aware of each sender and receiver, and a mapping request can be initiated here.
In the subsequent walkthrough, we will deploy a Sender contract on Mumbai (Polygon Testnet) and a Receiver contract on Ramestta Testnet.Following that, we will transmit data from the Sender and read the data on the Receiver using web3 calls in a node script.
Deploy Sender Contract: The Sender contract's primary function is to call the 'syncState' function on the StateSender contract, which is Rama's state syncer contract. The deployed addresses for Mumbai and Polygon Mainnet are as follows:
Mumbai: 0x924eEb1aeB7860Dce05546e6116D5bE1F2e8291A
Polygon Mainnet: 0xE0C9051E655380D1d880b9B0f4b500cEbD09278f
The Sender.sol contract code is as follows:
Use Remix to deploy the contract and note the address and ABI.
Deploy Receiver Contract: The Receiver contract is invoked by a Validator when the 'StateSynced' event is emitted. The Validator triggers the 'onStateReceive' function on the Receiver contract to submit the data.
The Receiver.sol contract code is as follows:
Deploy Receiver.sol on Ramestta Testnet and note the address and ABI.
Mapping Sender and Receiver: Use the deployed addresses or deploy custom contracts and request a mapping here.
Sending and Receiving Data: Write a node script to send arbitrary hex bytes, receive them on Puppynet, and interpret the data.
The complete script is as follows:
Run the script using node test
. A successful execution will provide an output similar to:
Last updated