Send a message from L2 Polygon zkEVM testnet to L1 Goerli.
There's two contracts; L2Contract.sol and L1Contract.sol
The L2 contract has a method sendGreetingMessageToL1 that sends a message form L2 to L1 contract to set a greeting message on L1 contract.
It sends the encoded calldata to execute setGreeting on L1 which can only be called if the message was sent by the L2 contract.
L2Contract.solL1Contract.soldeployL2.jsdeployL1.jssendL2ToL1Message.jswaitForInclusion.jsfinalizeMessageOnL1.jsgetGreetingOnL1.js
git clone https://github.com/miguelmota/polygon-zkevm-messenger-l2-to-l1-example.git
cd polygon-zkevm-messenger-l2-to-l1-example
npm installCreate .env
PRIVATE_KEY=123...Make sure private key has funds on both Polygon zkEVM testnet and Goerli.
npx hardhat compileCommand
npx hardhat run --network polygonzkevm scripts/deployL2.jsOutput
L2Contract deployed to: 0x8Da765bB3F8fbcae3647Fc326D1F7d3337a5882ACommand
L2_CONTRACT=0x8Da765bB3F8fbcae3647Fc326D1F7d3337a5882A \
npx hardhat run --network goerli scripts/deployL1.jsOutput
L1Contract deployed to: 0xd7f8d5a683D51fF90Aff7C25430CA3abAe3F80A0Command (replace env vars with your values)
GREETING="hello world" \
L2_CONTRACT=0x8Da765bB3F8fbcae3647Fc326D1F7d3337a5882A \
L1_CONTRACT=0xd7f8d5a683D51fF90Aff7C25430CA3abAe3F80A0 \
npx hardhat run --network polygonzkevm scripts/sendL2ToL1Message.jsOutput
sent tx hash 0x0085f32974b2b847bacb829f9006d89248cc6e53e3fb86f45cc348d94542ca22
https://testnet-zkevm.polygonscan.com/tx/0x0085f32974b2b847bacb829f9006d89248cc6e53e3fb86f45cc348d94542ca22Command
L2_TX_HASH=0x0085f32974b2b847bacb829f9006d89248cc6e53e3fb86f45cc348d94542ca22 \
L1_CONTRACT=0xd7f8d5a683D51fF90Aff7C25430CA3abAe3F80A0 \
npx hardhat run --network polygonzkevm scripts/waitForInclusion.jsOutput
Waiting for L1 root inclusion (this may take up to 60 minutes)...
{
"leaf_type": 1,
"orig_net": 1,
"orig_addr": "0x8Da765bB3F8fbcae3647Fc326D1F7d3337a5882A",
"amount": "0",
"dest_net": 0,
"dest_addr": "0xd7f8d5a683D51fF90Aff7C25430CA3abAe3F80A0",
"block_num": "569430",
"deposit_cnt": "23516",
"network_id": 1,
"tx_hash": "0x0085f32974b2b847bacb829f9006d89248cc6e53e3fb86f45cc348d94542ca22",
"claim_tx_hash": "",
"metadata": "0xa41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000",
"ready_for_claim": true
}
Ready to finalize messageCommand
L2_TX_HASH=0x0085f32974b2b847bacb829f9006d89248cc6e53e3fb86f45cc348d94542ca22 \
L1_CONTRACT=0xd7f8d5a683D51fF90Aff7C25430CA3abAe3F80A0 \
L2_CONTRACT=0x8Da765bB3F8fbcae3647Fc326D1F7d3337a5882A \
npx hardhat run --network goerli scripts/finalizeMessageOnL1.jsOutput
sent tx hash 0xcaae7ee9dd1f8657a21f4598a4c8a9e97cd1341ddf1ca988ad371641bc3993af
https://goerli.etherscan.io/tx/0xcaae7ee9dd1f8657a21f4598a4c8a9e97cd1341ddf1ca988ad371641bc3993afCommand
L1_CONTRACT=0xd7f8d5a683D51fF90Aff7C25430CA3abAe3F80A0 \
npx hardhat run --network goerli scripts/getGreetingOnL1.jsOutput
greeting: hello worldSee https://github.com/miguelmota/polygon-zkevm-messenger-l1-to-l2-example