Skip to content

Instantly share code, notes, and snippets.

@adilanchian
Last active November 2, 2023 06:07
Show Gist options
  • Star 80 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save adilanchian/9f745fdfa9186047e7a779c02f4bffb7 to your computer and use it in GitHub Desktop.
Save adilanchian/9f745fdfa9186047e7a779c02f4bffb7 to your computer and use it in GitHub Desktop.
Section 2: Write and deploy your WavePortal smart contract to a local Ethereum network
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();
console.log('WavePortal address: ', portal.address);
};
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
};
runMain();
const main = async () => {
const [owner, randoPerson] = 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(randoPerson).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();
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract WavePortal {
uint256 totalWaves;
constructor() {
console.log("Yo yo, I am a contract am I am smart");
}
function wave() public {
totalWaves += 1;
console.log("%s has waved!", msg.sender);
}
function getTotalWaves() public view returns (uint256) {
console.log("We have %d total waves!", totalWaves);
return totalWaves;
}
}
@lesenelir
Copy link

🍭

@0xBigotry
Copy link

awesome

@a4soon
Copy link

a4soon commented Dec 19, 2022

I am here and I am on track with your code, Farza!

@zkyuki
Copy link

zkyuki commented Dec 20, 2022

done

@Dextron04
Copy link

Done with the first part!!!

@tleecode
Copy link

tleecode commented Jan 3, 2023

Love this

@faisal-w
Copy link

faisal-w commented Jan 7, 2023

Done!!!

@jsrzx
Copy link

jsrzx commented Jan 10, 2023

Done!!!

@bajaj-aditya
Copy link

Awesome shit, Farza!!

@jianlin666
Copy link

This is awesome. Great job contributors!!!

@krote
Copy link

krote commented Jan 16, 2023

Done!!!

@iceonme
Copy link

iceonme commented Feb 1, 2023

Done,thank you Farza!

@MayuR45
Copy link

MayuR45 commented Feb 6, 2023

done!

@TheThai212
Copy link

niceee!

@LucasToMoon
Copy link

Nice!

@herata
Copy link

herata commented Feb 9, 2023

done sir!

@HiLakshya
Copy link

HiLakshya commented Feb 11, 2023

Done
image

@DevCheesard
Copy link

done! It's been a beautiful journey so far. Thanks for your help

@MohsinNaseer50
Copy link

Thanks

@iafhurtado
Copy link

Muchas gracias!

@iliacodes
Copy link

Thanks Farza!

@swk777
Copy link

swk777 commented Mar 10, 2023

thx

@anescaper
Copy link

i love u 😘

@YYBer
Copy link

YYBer commented Apr 26, 2023

Thankssss! Easy to unterstand and follow:)

@ShamimMiah
Copy link

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment