Skip to content

Instantly share code, notes, and snippets.

@Turupawn
Last active April 24, 2024 18:00
Show Gist options
  • Save Turupawn/caf375eb3bfdd76425cd5f2c5c862259 to your computer and use it in GitHub Desktop.
Save Turupawn/caf375eb3bfdd76425cd5f2c5c862259 to your computer and use it in GitHub Desktop.

Documentación oficial

https://docs.scroll.io/en/developers/guides/scroll-messenger-cross-chain-interaction/

Greeter

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

// This Greeter contract will be interacted with through the ScrollMessenger across the bridge
contract Greeter {
  string public greeting = "Hello World!";

  // This function will be called by executeFunctionCrosschain on the Operator Smart Contract
  function setGreeting(string memory greeting_) public {
    greeting = greeting_;
  }
}

Operador

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

// The Scroll Messenger interface is the same on both L1 and L2, it allows sending cross-chain transactions
// Let's import it directly from the Scroll Contracts library
import "@scroll-tech/contracts@0.1.0/libraries/IScrollMessenger.sol";

// The GreeterOperator is capable of executing the Greeter function through the bridge
contract GreeterOperator {
  // This function will execute setGreeting on the Greeter contract
  function executeFunctionCrosschain(
    address scrollMessengerAddress,
    address targetAddress,
    uint256 value,
    string memory greeting,
    uint32 gasLimit
  ) public payable {
    IScrollMessenger scrollMessenger = IScrollMessenger(scrollMessengerAddress);
    // sendMessage is able to execute any function by encoding the abi using the encodeWithSignature function
    scrollMessenger.sendMessage{ value: msg.value }(
      targetAddress,
      value,
      abi.encodeWithSignature("setGreeting(string)", greeting),
      gasLimit,
      msg.sender
    );
  }
}

Messenger

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.24;

interface IL1ScrollMessenger {
    event UpdateMaxReplayTimes(uint256 oldMaxReplayTimes, uint256 newMaxReplayTimes);
    struct L2MessageProof {
        // The index of the batch where the message belongs to.
        uint256 batchIndex;
        // Concatenation of merkle proof for withdraw merkle trie.
        bytes merkleProof;
    }
    function relayMessageWithProof(
        address from,
        address to,
        uint256 value,
        uint256 nonce,
        bytes memory message,
        L2MessageProof memory proof
    ) external;
}

Finalización en L2

L1
0x632Fcb26BDd71F949b4bAE71A0fF267c9390e0EF
L2
0xa6bf9202347160C2b7D89c82390Cb1cEE15375d2
Prueba
https://sepolia-api-bridge-v2.scroll.io/api/l2/unclaimed/withdrawals?page_size=10&page=1&address=0xa6bf9202347160C2b7D89c82390Cb1cEE15375d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment