Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions stepxx_web3/step04_hardhat/step00-setup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts

42 changes: 42 additions & 0 deletions stepxx_web3/step04_hardhat/step00-setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
1 - Install Node js. If your version of Node.js is older and not supported by Hardhat follow the instructions below to upgrade.
2 - Creating a new Hardhat project:

```
mkdir hardhat-tutorial
cd hardhat-tutorial
npm init
npm install --save-dev hardhat
npx hardhat
```

select typescript project

Tasks
Every time you're running Hardhat from the command-line, you're running a task. For example, npx hardhat compile is running the compile task. To see the currently available tasks in your project, run npx hardhat. Feel free to explore any task by running npx hardhat help [task].

```
npm install --save-dev @nomicfoundation/hardhat-toolbox
```

3 - Compile project:

```
npx hardhat compile
```

It will convert your contract into byte code and Create ABI.

4 - Test your contract:

```
npx hardhat test
```

5 - Deploy your project:

```
npx hardhat run scripts/deploy.ts
```

--network localhost: (it is used to deploy)
gives all information about the node, contract deployment, address, eth, from, gas used, and block no
34 changes: 34 additions & 0 deletions stepxx_web3/step04_hardhat/step00-setup/contracts/Lock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

// Uncomment this line to use console.log
// import "hardhat/console.sol";

contract Lock {
uint public unlockTime;
address payable public owner;

event Withdrawal(uint amount, uint when);

constructor(uint _unlockTime) payable {
require(
block.timestamp < _unlockTime,
"Unlock time should be in the future"
);

unlockTime = _unlockTime;
owner = payable(msg.sender);
}

function withdraw() public {
// Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal
// console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp);

require(block.timestamp >= unlockTime, "You can't withdraw yet");
require(msg.sender == owner, "You aren't the owner");

emit Withdrawal(address(this).balance, block.timestamp);

owner.transfer(address(this).balance);
}
}
8 changes: 8 additions & 0 deletions stepxx_web3/step04_hardhat/step00-setup/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
solidity: "0.8.9",
};

export default config;
Loading