Skip to content

Commit

Permalink
enforced tx guide draft + finalizing tx on L1 doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Turupawn committed Aug 8, 2023
1 parent 7df87b1 commit 077fe93
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
section: developers
date: Last Modified
title: "Sending an Enforced Transaction from Sepolia Etherscan"
lang: "en"
permalink: "developers/guides/enforced-tx-from-sepolia-etherscan"
excerpt: "The Enforced Transaction deployed on Sepolia is the most direct and permisionless way to send a transaction from L1 to L2. In this guide we will launch a Greeter contract on L2 and set the greeter value from Sepolia L1 from the Sepolia Etherscan UI."
---

import Aside from "../../../../../components/Aside.astro"
import ClickToZoom from "../../../../../components/ClickToZoom.astro"

import enforcedTxData from "../_images/enforcedTxData.png"
import enforcedTxSepoliascan from "../_images/enforcedTxSepoliascan.png"

The Enforced Transaction deployed on Sepolia is the most direct and permisionless way to send a transaction from L1 to L2. In this guide we will launch a Greeter contract on L2 and set the greeter value from Sepolia L1 from the Sepolia Etherscan UI.

#### Target Smart Contract

Let’s start by deploying the target smart contract on Scroll testnet. On this guide we will be using a Greeter contract and we will use Remix to deploy it and interact with it. Keep in mind that you can deploy any other contract with the tool of your choice.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
// This Greeter contract will be interacted with through the EnforcedTransaction contract deployed on Sepolia
contract Greeter {
string public greeting = "Hello World!";
// This function will be called by sendTransaction on Sepolia
function setGreeting(string memory greeting_) public {
greeting = greeting_;
}
// This function is not mandatory, is just a convinient way of getting the data needed to execute the setGreeting function from an external source
function getEncodedData(string memory greeting_) public pure returns (bytes memory) {
return abi.encodeWithSignature("setGreeting(string)", greeting_);
}
}
```

Once your contract contract is deployed, execute the `getEncodedData` by passing as parameter the new greeting that will be set from L1, try passing `“Crosschain message!”` as parameter. It will return a big sequence of bytes. Save both the result of the function call and the contract address because both will be needed later.

<ClickToZoom src={enforcedTxData} />

#### Sending an enforced transaction from Sepolia Etherscan

Now go to the [EnforcedTransaction contract tab](https://sepolia.etherscan.io/address/0x97f421ca37889269a11ae0fef558114b984c7487#writeProxyContract#F3) on Sepolia Scan and execute the sendTransaction by passing the following params:

- `payableAmount`: The amount of ETH used to pay gas on L2 `0.001` should be more than enough.
- `target`: The address of the Greeter smart contract deployed on L2.
- `value`: Pass 0 as param becuase the `setGreeting` function is not payable.
- `gasLimit`: The amount gas limit to execute the transaction on L2. `200000` should be enough.
- `data`: The big sequence of bytes you got from calling the `getEncodedData` function on your Greeter contract.

<ClickToZoom src={enforcedTxSepoliascan} />

After executing and confirming the transaction on Sepolia, the new state of `greeting` on the `Greeter` contract should be `“Crosschain message!”` or any message you set when calling `getEncodedData`. Sending a message from Sepolia to Scroll testnet should take around 20mins after the transactions are confirmed on Sepolia.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ permalink: "developers/guides/greeting-contract-with-cross-chain-interaction"
excerpt: "In this example, we will launch a dummy smart contract on either Sepolia or Scroll testnet and interact with it from the opposite chain."
---

import Aside from "../../../../../components/Aside.astro"

In this example, we will launch a dummy smart contract on either Sepolia or Scroll testnet and interact with it from the opposite chain. We will be using the `ScrollMessenger` that is deployed on both Sepolia and Scroll testnet.

#### Target Smart Contract
Expand Down Expand Up @@ -71,7 +73,18 @@ We pass the message by executing the `executeFunctionCrosschain` by passing the
- `targetAddress`: The address of the `Greeter` contract on the opposite chain.
- `value`: In this case, it is `0` because the `setGreeting`is not payable.
- `greeting`: This is the parameter that will be sent through the message. Try passing `“This message was crosschain!”`
- `gasLimit`: If you are sending the message from L1 to L2, around `5000` gas limit should be more than enough. If you are sending this from L2 to L1, you can pass `0` because this is an optional parameter.
- `gasLimit`: If you are sending the message from L1 to L2, around `5000` gas limit should be more than enough. If you are sending this from L2 to L1, you can pass `0` because this is an optional parameter since the transaction will need to be finalized by executing an extra transaction on L1.

<Aside type="caution" title="">
When a transaction is sent from L2 to L1 you will also need to call `relayMessageWithProof` on the Scroll Messanger
contract. You can do it directly on Sepolia Scan
[here](https://sepolia.etherscan.io/address/0x50c7d3e7f7c656493d1d76aaa1a836cedfcbb16a#writeProxyContract#F3). You
will need to pass the ZK proof of the batch and other paramaters that you can query on the Scroll API using this
format: `https://sepolia-api-bridge.scroll.io/api/claimable?address=GREETEROPERATORADDRESSONL2&page_size=10&page=1`
where `GREETEROPERATORADDRESSONL2` is your GreeterOperator contract address launched on L2. If you want to know more
information abut Finalizng transactions on L2 please refere to the [Scroll Messenger
documentation](../l1-and-l2-bridging/the-scroll-messenger).
</Aside>

After executing and confirming the transaction on both L1 and L2, the new state of `greeting` on the `Greeter` contract should be `“This message was crosschain!”`. Sending a message from one chain to the other should take around 20mins after the transactions are confirmed on the origin chain.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ the messenger smart contract deployed on L1. If you want to send a message from
When sending a transaction through the **Scroll Messenger** deployed on L1 and L2, the resulting transaction sender
(`CALLER` or `msg.sender`) will be the Messenger Contract address deployed on the receiving chain. In future Scroll
versions, enforced transactions will be introduced as a L1 contract. Sending enforced transactions will allow setting
the sender on L2 as the original one on L1. It will also allow 3rd parties to relay signed transactions and also
setting the&#x20;
the sender on L2 as the original one on L1. It will also allow 3rd parties to relay signed transactions in a secure
way.
</Aside>

### Finalizing transactions from L2
### Finalizing transactions on L1

Any upcoming transactions from L2 need to be finalized using the `relayMessageWithProof` function on the Scroll Messenger
contract. This includes both arbitrary messages and transfering assets through a gateway or the router. When you use
Expand Down Expand Up @@ -84,6 +84,13 @@ The `claimInfo` object under the `result` json returned has all the information
parameters needed by the `relayMessageWithProof` are: `from`, `to`, `value`, `nonce`, `message` and `proof`. Supply them to
the `relayMessageWithProof` function on L1 to execute and finalize your transaction on L1.

<Aside type="tip" title="">
All L2 transactions are boundled into batches, you have to wait for the batch where your transaction is included to
finish before calling `relayMessageWithProof`. Your transaction batch index is returned in the `batch_index` value on
the `/claimable` endpoint and you can follow the progress on the [Scroll Rollup
Scan](https://sepolia--scroll-io.netlify.app/rollupscan?page=1&per_page=10).
</Aside>

## Messenger API

Please visit the [npm library](https://www.npmjs.com/package/@scroll-tech/contracts?activeTab=code) for the complete Scroll contract API documentation.
Expand Down

0 comments on commit 077fe93

Please sign in to comment.