DEV Community

Cover image for Arbitrum Optimistc Rollups: Deploy de un Hola Mundo! en Testnet
Ahmed Castro
Ahmed Castro

Posted on • Updated on

Arbitrum Optimistc Rollups: Deploy de un Hola Mundo! en Testnet

Arbitrum está muy cerca de lanzar en Mainnet y estas son buenas noticias Ethereum.

Arbitrum es un protocolo de Layer 2 que implementa su propia versión de Optimistic Rollups. Arbitrum Testnet en Rinkeby ya fue lanzado así que en este video vamos a deployar un Smart Contract en dicho Testnet.

Asumiremos que estás familiarizado con Hardhat, te recomiendo este video si necesitas un repaso.

1. Preparativos

Asegúrate de tener fondos de Rinkeby en tu wallet de Metamask antes de iniciar. Puedes conseguirlos en el Faucet de Rinkeby.

  1. Dirígete hacia el Bridge de Arbitrum teniendo seleccionada la red de Rinkeby
  2. Agrega la red de Arbitrum Rinkeby en tu metamask haciendo click en "Add/Switch to Arbitrum Network"
  3. En tu wallet de Metamask y transfiere fondos desde "ETH on L1" hasta "ETH on L2".

Arbitrum Bridge

Luego de esperar un rato deberías ver reflejado tu nuevo saldo en Metamask en la red de Arbitrum Rinkeby.

Arbitrum Rinkeby en Metamask

2. Lanzar un contrato en Arbitrum Testnet

Es bastante similar a lanzar un contrato en cualquier otra red. La única diferencia es cómo agregamos la red de arbitrum en hardhat.config.js.

mkdir MyHardhatProject
cd MyHardhatProject
npm install -save-dev hardhat
npx hardhat
Enter fullscreen mode Exit fullscreen mode

Borramos el contrato contracts/Greeter.sol y lo reemplazamos el siguiente:

contracts/MyContract.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.5;

contract MyContract {
    string public hello;

    constructor()
    {
        hello = "Hola mundo!";
    }

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

hardhat.config.js

require("@nomiclabs/hardhat-waffle");

const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  solidity: "0.8.5",
  networks: {
    arbitrum: {
      url: `https://rinkeby.arbitrum.io/rpc`,
      gasPrice: 0,
      accounts: {mnemonic: mnemonic},
    }
  },
};
Enter fullscreen mode Exit fullscreen mode

scripts/sample-script.js

const hre = require("hardhat");

async function main() {
  const MyContract = await hre.ethers.getContractFactory("MyContract");
  const my_contract = await MyContract.deploy();

  await my_contract.deployed();

  console.log("MyContract deployed to:", my_contract.address);
}
main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

Enter fullscreen mode Exit fullscreen mode

⚠️⚠️⚠️Copia tu Secret Recovery Phrase de Metamask en un archivo vacío y llámalo .secret. Agregalo a tu .gitignore. ¡No olvides agregarlo a tu .gitignore!⚠️⚠️⚠️

.gitignore

.secret
Enter fullscreen mode Exit fullscreen mode
npx hardhat run --network arbitrum scripts/sample-script.js
Enter fullscreen mode Exit fullscreen mode

3. Interactuar con el contrato

Interactuar con un contrato en Arbitrum Testnet a través de HardHat también es muy similar a hacerlo con cualquier otra red.

npx hardhat console --network arbitrum
Enter fullscreen mode Exit fullscreen mode

Una vez dentro de la consola interactuamos con el contrato. Asegurate de agregar el address de tu contrato cuando ejecutes la funcion attack.

const MyContract = await ethers.getContractFactory("MyContract")
const my_contract = await MyContract.attach("0x5FbDB2315678....")
await my_contract.hello()
await my_contract.setHello("Probando...")
await my_contract.hello()
Enter fullscreen mode Exit fullscreen mode

Documentació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.

Latest comments (0)