Interoperabilidad Layer 1 y Layer 2

Ahmed Castro - Apr 29 '22 - - Dev Community

Poco a poco vemos como diferentes soluciones de escalabilidad de blockchain se hacen realidad. Estas soluciones cada vez ahorran mas gas sin sacrificar seguridad. En este video probaremos la interoperabilidad entre Ethereum Mainnet (Layer 1) y Arbitrum (Optimistic Rollup de Ethereum Layer 2). Los bridges entre Mainnet y los Rollups traen nuevas mecánicas al blockchain y son la manera mas segura y avanzada de operar smart contracts generéricos cross chain. La buena noticia es que ya están disponibles hoy para nosotros los programadores y los usuarios del blockchain.

https://youtu.be/_RFs2TfsKI

Antes de iniciar

Asegurate de instalar Metamask y agregar fondos de Rinkeby Testnet que puedes conseguir desde el Faucet. También necesitarás agregar Rinkeby Arbitrum Testnet a tu metamask mover fondos desde Rinkeby a Rinkeby Arbitrum Testnet mediante el Bridge.

Contrato en L2

Primero lanzamos el siguiente contrato en Arbitrum Rinkeby Testnet.

// SPDX-License-Identifier: Apache-2.0
pragma solidity  0.8.13;

contract HelloWorld {
    string public hello = "Hola Mundo!";

    function setHello(string memory _hello) public {
        hello = _hello;
    }
}
Enter fullscreen mode Exit fullscreen mode

Contrato operador en L1

Luego lanzamos el siguiente contrato y ejecutamos la función setHelloInL2 pasando como value 20000000000000000 wei o 0.01 ether y los siguientes parametros sugeridos:

  • l2ContractAddress: ADDRESS DE CONTRATO EN L2
  • _hello: ¡Hemos ejecutado esto desde L1!
  • maxSubmissionCost: 80000000000
  • maxGas: 90000000
  • gasPriceBid: 90000000
// SPDX-License-Identifier: Apache-2.0
pragma solidity  0.8.13;


interface IInbox {
    function createRetryableTicket(
        address destAddr,
        uint256 l2CallValue,
        uint256 maxSubmissionCost,
        address excessFeeRefundAddress,
        address callValueRefundAddress,
        uint256 maxGas,
        uint256 gasPriceBid,
        bytes calldata data
    ) external payable returns (uint256);
}

interface IHelloWorld {
    function setHello(string memory _hello) external;
}

contract L2Operator {
    IInbox public inbox = IInbox(0x578BAde599406A8fE3d24Fd7f7211c0911F5B29e);

    function setHelloInL2(
        address l2ContractAddress,
        string memory _hello,
        uint256 maxSubmissionCost,
        uint256 maxGas,
        uint256 gasPriceBid
    ) public payable returns (uint256) {
        bytes memory data =
            abi.encodeWithSelector(IHelloWorld.setHello.selector, _hello);
        uint256 ticketID = inbox.createRetryableTicket{value: msg.value}(
            l2ContractAddress,
            0,
            maxSubmissionCost,
            msg.sender,
            msg.sender,
            maxGas,
            gasPriceBid,
            data
        );
        return ticketID;
    }
}
Enter fullscreen mode Exit fullscreen mode

Documetación oficial:

¡Gracias por ver este tutorial!

Sígueme en dev.to y en Youtube para todo lo relacionado al desarrollo en Blockchain en Español.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player