Created
April 29, 2022 21:33
-
-
Save danicuki/4659b861398c9143b86d07752e066ea6 to your computer and use it in GitHub Desktop.
Seção 1: Escrever e deployar o contrato inteligente WavePortal na rede local Ethereum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const main = async () => { | |
| const [deployer] = await hre.ethers.getSigners(); | |
| const accountBalance = await deployer.getBalance(); | |
| console.log("Deploying contracts with account: ", deployer.address); | |
| console.log("Account balance: ", accountBalance.toString()); | |
| const Token = await hre.ethers.getContractFactory("WavePortal"); | |
| const portal = await Token.deploy(); | |
| await portal.deployed(); | |
| console.log("WavePortal address: ", portal.address); | |
| }; | |
| const runMain = async () => { | |
| try { | |
| await main(); | |
| process.exit(0); | |
| } catch (error) { | |
| console.error(error); | |
| process.exit(1); | |
| } | |
| }; | |
| runMain(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const main = async () => { | |
| const [owner, randomPerson] = await hre.ethers.getSigners(); | |
| const waveContractFactory = await hre.ethers.getContractFactory("WavePortal"); | |
| const waveContract = await waveContractFactory.deploy(); | |
| await waveContract.deployed(); | |
| console.log("Contract deployed to:", waveContract.address); | |
| console.log("Contract deployed by:", owner.address); | |
| let waveCount; | |
| waveCount = await waveContract.getTotalWaves(); | |
| let waveTxn = await waveContract.wave(); | |
| await waveTxn.wait(); | |
| waveCount = await waveContract.getTotalWaves(); | |
| waveTxn = await waveContract.connect(randomPerson).wave(); | |
| await waveTxn.wait(); | |
| waveCount = await waveContract.getTotalWaves(); | |
| }; | |
| const runMain = async () => { | |
| try { | |
| await main(); | |
| process.exit(0); | |
| } catch (error) { | |
| console.log(error); | |
| process.exit(1); | |
| } | |
| }; | |
| runMain(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: UNLICENSED | |
| pragma solidity ^0.8.0; | |
| import "hardhat/console.sol"; | |
| contract WavePortal { | |
| uint256 totalWaves; | |
| constructor() { | |
| console.log("Ueba, eu sou um contrato e eu sou inteligente"); | |
| } | |
| function wave() public { | |
| totalWaves += 1; | |
| console.log("%s deu tchauzinho!", msg.sender); | |
| } | |
| function getTotalWaves() public view returns (uint256) { | |
| console.log("Temos um total de %d tchauzinhos!", totalWaves); | |
| return totalWaves; | |
| } | |
| } |
Muito bom! Vamos que Vamos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tudo ok, vamos em frente!