Introducci贸n al desarrollo en Capa 2
Desarrollando en capa 2
Introducci贸n al desarrollo en capa 2
Desarrollo en Optimistic Rollups
Obteniendo fondos en un tesnet de capa 2
Lanzando un token en Arbitrum
Frontend para DApps
Intercomunicaci贸n entre capas
Desarrollo en zkRollups
Lanzamiento de NFTs en Immutable X
Smart Contracts con Cairo en Starknet
Utilizando el SDK de zkSync 2.0
Desaf铆os t茅cnicos de los zkRollups
You don't have access to this class
Keep learning! Join and start boosting your career
The real magic of second-layer protocols lies in the full compatibility with the underlying blockchain. All the information that is generated in a contract at Layer 1 can be sent to Layer 2 (and vice versa) via a bridge.
Just as you can use bridges between Layer 1 and 2 to move funds, you can also use them to send data, execute functions between contracts or obtain information.
These bridges are still smart contracts deployed at Layer 1, which allow you to communicate with contracts at Layer 2. You must locate these contracts on the network where you are in order to use them. For example, if we are on the Goerli
testnet, we will find contract 0x5086...bE294 which represents the bridge to the Optimism testnet.
To run a function on a contract deployed in Optimism from Ethereum Goerli
, start by deploying in L2 the contract in question that you want to run from L1.
```c // SPDX-License-Identifier: MIT pragma solidity 0.8.17;
contract HelloWorld { string public hello = "Hello world!";
function setHello(string memory hello hello_) public { hello = hello_; }
} ```
A simple contract to persist a message of type string
. To deploy it in Optimism, you will need funds which you can obtain by using this bridge to send some ETH from Goerli. You will also need to add the network to your Metamask, you can do this from the Optimism Goerli browser.
Next, place yourself in Remix, or your preferred development environment, to deploy a contract on L1. The contract that will communicate with L2 will be as follows:
````c // SPDX-License-Identifier: MIT pragma solidity 0.8.17;
interface CrossDomainMessenger { function sendMessage(address _target, bytes memory _message, uint32 _minGasLimit) payable external; }
contract HelloWorldOperatorL1 { // We instantiate the bridge with its CrossDomainMessenger address ovmL1CrossDomainMessenger = CrossDomainMessenger(0x5086d1eEF304eb5284A0f6720f79403b4e9bE294);
function executeFuncionInL2(address l2ContractAddress, string memory hello_, uint32 gasLimit) public { ovmL1CrossDomainMessenger.sendMessage( l2ContractAddress, abi.encodeWithSignature( "setHello(string)", hello_ ), gasLimit ); }
} ```
If you look in detail at the bridge, 0x5086...bE294, the sendMessage()
function will allow you to execute a function on a contract in L2.
For this, we make use of a custom interface in our contract called CrossDomainMessenger
to instantiate the bridge to recognize the sendMessage()
function. Then, we use the abi
object that will help us encrypt the message and send it to L2 when the executeFunctionInL2
function is executed.
Deploy this contract in L1 and when the above function is executed, you can see the change of the message that we stored in the contract of the second layer. This transaction must be committed in both layers, so it will take a few minutes to see the changes reflected.
We have made a very simple example to send a text message from Layer 1 to Layer 2. But this is enough to appreciate how powerful and interesting can be the communication of contracts in different layers.
Contributed by: Kevin Fiorentino.
Contributions 2
Questions 1
El contrato 0x5086d1eEF304eb5284A0f6720f79403b4e9bE294 es el bridge entre Ethereum y Optimisms en Goerli. Por aqu铆 encontr茅 algunos contratos de Optimism para construir los puentes con Ethereum.
Want to see more contributions, questions and answers from the community?