Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Can we transmit messages via the Supernets bridge instead of tokens? #1999

Closed
sahil3Vedi opened this issue Oct 19, 2023 · 2 comments
Closed

Comments

@sahil3Vedi
Copy link

Is it possible to transmit messages via the Supernets bridge?

Description

We'd like to monitor an event E1 (on some smart contract) on the Rootchain and trigger another event E2 on some smart contract on the Supernet.

Normally we can use event listeners from go-ethereum or ethersjs to listen for events. Does the Supernets bridge support message transfer or would it be advisable to setup our own service to listen for smart contract events?

Your environment

  • Ubuntu 22.04
  • Supernets v1.3
@goran-ethernal
Copy link
Collaborator

Even though it is not intended for that, bridge on Supernets can be used for basically transferring any data from a root chain to Edge and vice versa.

To transfer data from L1 to L2:

We use the StateSender contract on L1. It's a contract that emits a generic event:
event StateSynced(uint256 indexed id, address indexed sender, address indexed receiver, bytes data); in the syncState function. So you would basically need to call this contract from your contract on L1, and specify the receiver address on L2, and data you want to send.
Validators on Supernet will catch this event that happened on root, create a commitment and submit it to StateReceiver contract on Supernet. After that is submitted, the relayer node will execute that event, by basically sending a transaction to the receiver contract on Supernet you specified when calling the StateSender on L1, with given data. But be aware that receiver contract has to implement onStateReceive(uint256,address,bytes) function.

To send data from L2 to L1

We use the L2StateSender contract. Basically it is an L2 StateSender contract, that emits event L2StateSynced(uint256 indexed id, address indexed sender, address indexed receiver, bytes data);. You basically do the same steps as in transferring data from L1 to L2, you call this L2StateSender syncState function with address of the receiver contract on L1, and data you want to send.
Validators on Supernet catch these events, and submit a checkpoint to CheckpointManager contract on L1. After checkpoint is submitted to L1, a user needs to execute this L2StateSyncEvent on L1, by calling the exit function on ExitHelper contract on L1. Note that receiver contract on L1 has to implement onL2StateReceive(uint256,address,bytes) function.

You can read the Supernets documentation more about this, but as I said, it is possible to bridge any data back and forth.

@sahil3Vedi
Copy link
Author

Thanks for the clarification @goran-ethernal

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants