Wischain messenger Cross-chain Interaction
In this example, we will demonstrate how to deploy a simple smart contract on either Sepolia or Wischain and interact with it from the opposite chain using the Wischain Messenger, which is deployed on both Sepolia and Wischain.
Deploying the Contracts
Target Smart Contract
We will begin by deploying a target smart contract, the Greeter contract, which can be replaced with any other contract of your choice. This contract can be deployed to either Sepolia or Wischain. Note that both Layer 1 (L1) and Layer 2 (L2) in Wischain utilize the same API, so the choice is flexible.
Next, we will execute the setGreeting
function across the chains.
Operator Smart Contract
Switch to the opposite chain and deploy the GreeterOperator
contract. For instance, if you deployed the Greeter contract on L1, you should deploy the GreeterOperator on L2, and vice versa.
Calling a Cross-Chain Function
To initiate the cross-chain function, invoke executeFunctionCrosschain
with the following parameters:
wischainMessengerAddress: This address will depend on where you deployed the
GreeterOperator
contract. For deployment on Sepolia, use0x.....
. For deployment on Wischain Sepolia, use0x.....
.targetAddress: The address of the Greeter contract on the opposite chain.
value: In this case, it is
0
since thesetGreeting
function is not payable.greeting: The parameter sent through the message. For example, you could use “This message was cross-chain!”.
gasLimit:
If sending the message from L1 to L2, a gas limit of around 1,000,000 should suffice. However, if this is set too high and
msg.value
does not covergasLimit * baseFee
, the transaction will revert. Any unused portion will be refunded ifmsg.value
exceeds the gas fee.If sending from L2 to L1, pass
0
, as the transaction will complete with an additional transaction on L1.
Relaying the Message from L2 to L1
When a transaction is sent from L2 to L1, an additional “execute withdrawal transaction” must be initiated on L1. To achieve this, call relayMessageWithProof
on the L1 Wischain Messenger contract using an Externally Owned Account (EOA) wallet.
This can be executed directly on Wischainscan. You will need to provide a Merkle inclusion proof for the bridged transaction along with other parameters, which can be queried using the Wischain Bridge API.
Although the API specifics are still being finalized, you can fetch or execute the following endpoint:
Replace GREETER_OPERATOR_ADDRESS_ON_L2
with the address of your deployed GreeterOperator
contract on L2. For additional information about Execute Withdraw transactions, refer to the Wischain Messenger documentation.
Experimental API
This API was developed for our Bridge UI and is subject to change. We will update this guide once the API is finalized.
Permissionless Execution of L2 → L1 Messages
The relayMessageWithProof
function is fully permissionless, allowing anyone to invoke it on your behalf if they are willing to cover the L1 gas fees. This capability enables the development of additional support infrastructures, including tools to automate this process for both applications and users.
Once the transaction is executed and confirmed on both L1 and L2, the new state of the greeting in the Greeter contract should reflect “This message was cross-chain!”. Expect the process of sending a message from one chain to the other to take approximately 20 minutes after confirmation on the originating chain.
Congratulations! You have successfully executed a transaction across chains using the native Wischain bridge!
Last updated