Skip to content

Commit

Permalink
add live exo
Browse files Browse the repository at this point in the history
  • Loading branch information
ibourn committed Jun 21, 2023
1 parent b5120ed commit ec43e61
Show file tree
Hide file tree
Showing 22 changed files with 40,697 additions and 0 deletions.
1 change: 1 addition & 0 deletions 6. Dapp/3_1_web3/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
dotenv/
node_modules/
1 change: 1 addition & 0 deletions 6. Dapp/3_2_lectureSC/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
dotenv/
node_modules/
11 changes: 11 additions & 0 deletions 6. Dapp/Live_Hhat_SSdap/backend/.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

13 changes: 13 additions & 0 deletions 6. Dapp/Live_Hhat_SSdap/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.js
```
36 changes: 36 additions & 0 deletions 6. Dapp/Live_Hhat_SSdap/backend/contracts/Bank.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

error Bank__NotEnoughFundsProvided();
error Bank__NotEnoughEthersOnTheSC();
error Bank__WithdrawFailed();

/// @title A simple wallet contract
/// @author Ben BK
/// @notice Allows to send and withdraw Ethers from a smart contract

contract Bank {

mapping(address => uint) balances;

/// @notice Allows to send Ethers to the smart contract
function sendEthers() external payable {
if(msg.value < 1 wei) {
revert Bank__NotEnoughFundsProvided();
}
balances[msg.sender] += msg.value;
}

/// @notice Allows to withdraw Ethers from the smart contract
/// @param _amount The amount to withdraw
function withdraw(uint _amount) external {
if(_amount > balances[msg.sender]) {
revert Bank__NotEnoughEthersOnTheSC();
}
balances[msg.sender] -= _amount;
(bool received, ) = msg.sender.call{value: _amount}("");
if(!received) {
revert Bank__WithdrawFailed();
}
}
}
34 changes: 34 additions & 0 deletions 6. Dapp/Live_Hhat_SSdap/backend/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);
}
}
24 changes: 24 additions & 0 deletions 6. Dapp/Live_Hhat_SSdap/backend/contracts/SimpleStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

/// @title a simple storage contract
/// @author Ben BK

contract SimpleStorage {

uint private number;

/// @notice Set the number
/// @dev Nothing to say
/// @param _number the new number which will be in storage in the blockchain
function setNumber(uint _number) external {
number = _number;
}

/// @notice Get the number which is stored in the blockchain
/// @return Returns the number
function getNumber() external view returns(uint) {
return number;
}

}
6 changes: 6 additions & 0 deletions 6. Dapp/Live_Hhat_SSdap/backend/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require("@nomicfoundation/hardhat-toolbox");

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.20",
};
Loading

0 comments on commit ec43e61

Please sign in to comment.