Ethereum to Shibarium
In order to natively read Ethereum data from the Shibarium EVM chain, the mechanism utilized is known as 'State Sync'. This process facilitates the transfer of arbitrary data from the Ethereum chain to the Shibarium 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 Ethereum. 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 Goerli (Ethereum testnet) and a Receiver contract on Puppynet (Shibarium's 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 Bone's state syncer contract. The deployed addresses for Goerli and Ethereum Mainnet are as follows:
Goerli: 0xEAa852323826C71cd7920C3b4c007184234c3945
Ethereum Mainnet: 0x28e4F3a7f651294B9564800b2D01f35189A5bFbE
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 Puppynet 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