Waffle say hello world tutorial with hardhat and ethers
wafflesmart contractssoliditytestinghardhatethers.js
BeginnerIn this Waffle(opens in a new tab) tutorial, we will learn how to set up a simple "Hello world" smart contract project, using hardhat(opens in a new tab) and ethers.js(opens in a new tab). Then we will learn how to add a new functionality to our smart contract and how to test it with Waffle.
Let's start with creating new project:
yarn init
or
npm init
and installing required packages:
yarn add -D hardhat @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
or
npm install -D hardhat @nomiclabs/hardhat-ethers ethers @nomiclabs/hardhat-waffle ethereum-waffle chai
Next step is creating a sample hardhat project by running npx hardhat
.
888 888 888 888 888888 888 888 888 888888 888 888 888 8888888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888888 888 "88b 888P" d88" 888 888 "88b "88b 888888 888 .d888888 888 888 888 888 888 .d888888 888888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888👷 Welcome to Hardhat v2.0.3 👷? What do you want to do? …❯ Create a sample projectCreate an empty hardhat.config.jsQuit모두 보기
Select Create a sample project
Our project's structure should look like this:
1MyWaffleProject2├── contracts3│ └── Greeter.sol4├── node_modules5├── scripts6│ └── sample-script.js7├── test8│ └── sample-test.js9├── .gitattributs10├── .gitignore11├── hardhat.config.js12└── package.json13모두 보기
Now let's talk about some of these files:
- Greeter.sol - our smart contract written in solidity;
1contract Greeter {2string greeting;34constructor(string memory _greeting) public {5console.log("Deploying a Greeter with greeting:", _greeting);6greeting = _greeting;7}89function greet() public view returns (string memory) {10return greeting;11}1213function setGreeting(string memory _greeting) public {14console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);15greeting = _greeting;16}17}18