Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
}
@QChesthairQ
Copy link

I got TypeError: waveContract.getTotalWaves is not a function.
What it he root cause of this?

@Codeprime-21
Copy link

@QChesthairQ please check your code again properly. There must be some typing mistake..or you missed brackets while calling getTotalWaves function.

@QChesthairQ
Copy link

@Codeprime-21 I guess I am new to npx, so I figured it out it needs to be compiled before rerun the run.js

@Codeprime-21
Copy link

@QChesthairQ yup. errors needs the code snippet to be checked before concluding what the error is...😂
But yeah glad you figured it out! Good luck.

@lucasbastianik
Copy link

LFG! 🕺

@GerGodfrey
Copy link

awesome tuto !

@abraham-yusuf
Copy link

Done

@YanYuanFE
Copy link

done

@Aheesh
Copy link

Aheesh commented Nov 25, 2022

ok! That was worth it.

@mrsetia1
Copy link

Wow amazing, thank farza

@jturner3
Copy link

Deployed and looks great. Thanks Farza

@zklim
Copy link

zklim commented Nov 27, 2022

Thanks Farza!

@btcgirlboy
Copy link

Deployed and looks great. Thanks Farza

@kosmosr
Copy link

kosmosr commented Dec 1, 2022

It's intersting

@isaacpyn
Copy link

isaacpyn commented Dec 1, 2022

Excellent tutorial, hands on and cool!

@CASTVELL
Copy link

CASTVELL commented Dec 2, 2022

lfg

@hidayatgp1
Copy link

Easy tutorial! Excellent!
image

@suisuisui0722
Copy link

It was so much fun! exciting!

@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!!!

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