From e819356e68199c0d77d831d0e57ab285b655120d Mon Sep 17 00:00:00 2001 From: Tariq15994 Date: Mon, 28 Feb 2022 09:12:21 +0500 Subject: [PATCH 1/2] Code and explain every Topic in separate file --- step03_solidity_tutorial/contracts/Array.sol | 44 +++ step03_solidity_tutorial/contracts/Demo.sol | 44 +++ step03_solidity_tutorial/contracts/Demo1.sol | 34 --- .../contracts/Greeter.sol | 22 -- .../contracts/SolidityTest.sol | 43 --- .../contracts/SolidityTest2.sol | 79 ------ .../contracts/SolidityTest3.sol | 26 -- .../contracts/SolidityTest4.sol | 56 ---- .../contracts/SolidityTest5.sol | 39 --- .../contracts/SolidityTest6.sol | 75 ----- step03_solidity_tutorial/contracts/Types.sol | 38 +++ step03_solidity_tutorial/contracts/enum.sol | 52 ++++ .../contracts/fallback_recieve_func.sol | 60 ++++ .../contracts/functionVisibility.sol | 53 ++++ step03_solidity_tutorial/contracts/loop.sol | 47 ++++ step03_solidity_tutorial/contracts/math.sol | 39 +++ .../contracts/modifier.sol | 32 +++ .../contracts/overload.sol | 35 +++ step03_solidity_tutorial/contracts/string.sol | 32 +++ step03_solidity_tutorial/contracts/struct.sol | 96 +++++++ .../contracts/variables.sol | 40 +++ .../contracts/view_pure_funciton.sol | 33 +++ .../contracts/withdrawalPattern.sol | 53 ++++ step03_solidity_tutorial/scripts/Demo.ts | 31 +++ .../scripts/deploy-prac-contract.ts | 29 ++ step03_solidity_tutorial/scripts/deploy.ts | 256 ------------------ step03_solidity_tutorial/scripts/enum.ts | 39 +++ .../scripts/fallback_recieve_func.ts | 137 ++++++++++ .../scripts/functionVisiblity.ts | 28 ++ step03_solidity_tutorial/scripts/loop.ts | 24 ++ step03_solidity_tutorial/scripts/math.ts | 27 ++ step03_solidity_tutorial/scripts/modifier.ts | 73 +++++ step03_solidity_tutorial/scripts/overload.ts | 24 ++ .../scripts/sample-script.ts | 23 -- step03_solidity_tutorial/scripts/string.ts | 29 ++ step03_solidity_tutorial/scripts/struct.ts | 51 ++++ step03_solidity_tutorial/scripts/types.ts | 29 ++ step03_solidity_tutorial/scripts/variables.ts | 46 ++++ .../scripts/withDrawal.ts | 39 +++ 39 files changed, 1304 insertions(+), 653 deletions(-) create mode 100644 step03_solidity_tutorial/contracts/Array.sol create mode 100644 step03_solidity_tutorial/contracts/Demo.sol delete mode 100644 step03_solidity_tutorial/contracts/Demo1.sol delete mode 100644 step03_solidity_tutorial/contracts/Greeter.sol delete mode 100644 step03_solidity_tutorial/contracts/SolidityTest.sol delete mode 100644 step03_solidity_tutorial/contracts/SolidityTest2.sol delete mode 100644 step03_solidity_tutorial/contracts/SolidityTest3.sol delete mode 100644 step03_solidity_tutorial/contracts/SolidityTest4.sol delete mode 100644 step03_solidity_tutorial/contracts/SolidityTest5.sol delete mode 100644 step03_solidity_tutorial/contracts/SolidityTest6.sol create mode 100644 step03_solidity_tutorial/contracts/Types.sol create mode 100644 step03_solidity_tutorial/contracts/enum.sol create mode 100644 step03_solidity_tutorial/contracts/fallback_recieve_func.sol create mode 100644 step03_solidity_tutorial/contracts/functionVisibility.sol create mode 100644 step03_solidity_tutorial/contracts/loop.sol create mode 100644 step03_solidity_tutorial/contracts/math.sol create mode 100644 step03_solidity_tutorial/contracts/modifier.sol create mode 100644 step03_solidity_tutorial/contracts/overload.sol create mode 100644 step03_solidity_tutorial/contracts/string.sol create mode 100644 step03_solidity_tutorial/contracts/struct.sol create mode 100644 step03_solidity_tutorial/contracts/variables.sol create mode 100644 step03_solidity_tutorial/contracts/view_pure_funciton.sol create mode 100644 step03_solidity_tutorial/contracts/withdrawalPattern.sol create mode 100644 step03_solidity_tutorial/scripts/Demo.ts create mode 100644 step03_solidity_tutorial/scripts/deploy-prac-contract.ts delete mode 100644 step03_solidity_tutorial/scripts/deploy.ts create mode 100644 step03_solidity_tutorial/scripts/enum.ts create mode 100644 step03_solidity_tutorial/scripts/fallback_recieve_func.ts create mode 100644 step03_solidity_tutorial/scripts/functionVisiblity.ts create mode 100644 step03_solidity_tutorial/scripts/loop.ts create mode 100644 step03_solidity_tutorial/scripts/math.ts create mode 100644 step03_solidity_tutorial/scripts/modifier.ts create mode 100644 step03_solidity_tutorial/scripts/overload.ts delete mode 100644 step03_solidity_tutorial/scripts/sample-script.ts create mode 100644 step03_solidity_tutorial/scripts/string.ts create mode 100644 step03_solidity_tutorial/scripts/struct.ts create mode 100644 step03_solidity_tutorial/scripts/types.ts create mode 100644 step03_solidity_tutorial/scripts/variables.ts create mode 100644 step03_solidity_tutorial/scripts/withDrawal.ts diff --git a/step03_solidity_tutorial/contracts/Array.sol b/step03_solidity_tutorial/contracts/Array.sol new file mode 100644 index 0000000..17fa30d --- /dev/null +++ b/step03_solidity_tutorial/contracts/Array.sol @@ -0,0 +1,44 @@ +pragma solidity ^0.8.0; +import "hardhat/console.sol"; +// public private Variable Scope +contract String { + + + + + // 1. Dynamic arrays + // 2. Static arrays + // 3. Array arguments and return arrays from function + + //1. Dynamic Array + + uint[] public myArray; //Create, Read, Update, Delete + // This is dynamic size array here we are not specifing the array size + function storageArrays() public returns ( uint[] memory ) { + myArray.push(2); //add value in array + myArray.push(3); + myArray[0] = 20; // Updating array + + delete myArray[1]; // delete will not delete the value of given index + return myArray; + } + + //2. Static Array + function staticArray() public pure returns (uint[] memory) { + uint[] memory statArray = new uint[](10); //Create, Read, Update, Delete + // statArray.push(10)// we can't append value using push function in static type array + statArray[0] = 20; // add value in array + statArray[1]= 30; + + statArray[0] = 40; //update array + + delete statArray[1]; + return statArray; + } + // function getBytesName(string memory firstName, string memory lastName)public pure returns( bytes memory ) { + + // } + + +} + \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/Demo.sol b/step03_solidity_tutorial/contracts/Demo.sol new file mode 100644 index 0000000..b5535bb --- /dev/null +++ b/step03_solidity_tutorial/contracts/Demo.sol @@ -0,0 +1,44 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract Demo1 { + uint256 public balance; + string public name; + + constructor(string memory _name) { + name = _name; + } + + function getName() public view returns (string memory ) { + return name; + } + +} + +contract Demo2 { + address public demo1Address;//we create this variable of storing address of new contract + + function createExample(string memory _name) public returns(address ) { + /* + 1. This function create a instanse of Demo1 Contract with the of d1 + 2. Update the demo1Address to address of d1 + 3. Return the Address of d1 + */ + Demo1 d1 = new Demo1(_name); + demo1Address = address(d1); + return address(d1); + } + + function getNameOfContract(address _addr1)public view returns(string memory) { + /* + 1. This function takes address + 2. Create the new instanse and Pass this address to the Demo1 contract + 3. D1 return the Name of the given address + */ + Demo1 d1 = Demo1(_addr1); + return d1.getName(); + } + +} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/Demo1.sol b/step03_solidity_tutorial/contracts/Demo1.sol deleted file mode 100644 index 8c1a1b3..0000000 --- a/step03_solidity_tutorial/contracts/Demo1.sol +++ /dev/null @@ -1,34 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract Demo1 { - - uint256 public balance; - string public name; - - constructor(string memory _name) { - name = _name; - } - - function getName() public view returns(string memory) { - return name; - } -} - -contract Demo2 { - - address public demo1Address; - function createExample(string memory _name) public returns (address){ - Demo1 d1 = new Demo1(_name); - demo1Address = address(d1); - return address(d1); - } - - function getNameOfContract(address _addr1) public view returns(string memory){ - Demo1 d1 = Demo1(_addr1); - return d1.getName(); - } - -} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/Greeter.sol b/step03_solidity_tutorial/contracts/Greeter.sol deleted file mode 100644 index 34ceabc..0000000 --- a/step03_solidity_tutorial/contracts/Greeter.sol +++ /dev/null @@ -1,22 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract Greeter { - string private greeting; - - constructor(string memory _greeting) { - console.log("Deploying a Greeter with greeting:", _greeting); - greeting = _greeting; - } - - function greet() public view returns (string memory) { - return greeting; - } - - function setGreeting(string memory _greeting) public { - console.log("Changing greeting from '%s' to '%s'", greeting, _greeting); - greeting = _greeting; - } -} diff --git a/step03_solidity_tutorial/contracts/SolidityTest.sol b/step03_solidity_tutorial/contracts/SolidityTest.sol deleted file mode 100644 index 0eb1965..0000000 --- a/step03_solidity_tutorial/contracts/SolidityTest.sol +++ /dev/null @@ -1,43 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract SolidityTest { - - enum FreshJuiceSize { SMALL, MEDIUM, LARGE, EXTRALARGE } - - enum FundingRounds { - SEED, - PRIVATE, - PUBLIC - } - - uint256 abc = 45; - - FreshJuiceSize juice = FreshJuiceSize.MEDIUM; - - FundingRounds currentRound = FundingRounds.SEED; - - function getCurrentFundingRound() public view returns (FundingRounds) { - return currentRound; - } - - function changeRound(uint256 _round) public { - require(_round >= 0 && _round <=2,"Invalid Round Information"); - currentRound = FundingRounds(_round); - } - - function getJuice() public view returns(FreshJuiceSize) { - return juice; - } - - function updateJuiceSize(FreshJuiceSize _juice) public { - juice = _juice; - } - - function verifyJuiceSize() public view returns (bool) { - return juice == FreshJuiceSize.EXTRALARGE; - } - -} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/SolidityTest2.sol b/step03_solidity_tutorial/contracts/SolidityTest2.sol deleted file mode 100644 index 06adfe0..0000000 --- a/step03_solidity_tutorial/contracts/SolidityTest2.sol +++ /dev/null @@ -1,79 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract SolidityTest2 { - - enum FundingRounds { - SEED, - PRIVATE, - PUBLIC - } - - struct FundingRoundDetails { - uint256 fundingRequired; - FundingRounds round; - } - - FundingRoundDetails[] public allRounds; - - mapping(uint256 => FundingRoundDetails) fundingRounds; - - mapping(address => FundingRoundDetails) userRounds; - - mapping(address => mapping(uint256=>bool)) someMapping; - - uint256 roundCounter; - - struct UserInfo { - string name; - uint256 age; - mapping(address=>uint256) fundingReceived; - } - - mapping(address=>UserInfo) users; - - function addUser(string memory _name, uint256 _age) public { - //UserInfo memory _user = UserInfo("Zia Khan", 30); - - UserInfo storage _user = users[msg.sender]; - _user.name= _name; - _user.age = _age; - } - - function provideFunding(address _user, uint256 _amount) public { - UserInfo storage _userInfo = users[_user]; - _userInfo.fundingReceived[msg.sender] = _amount; - } - - function addFundingRounds() public { - FundingRoundDetails memory details1 = FundingRoundDetails(10000, FundingRounds.SEED); - FundingRoundDetails memory details2 = FundingRoundDetails(20000, FundingRounds.PRIVATE); - FundingRoundDetails memory details3 = FundingRoundDetails(30000, FundingRounds.PUBLIC); - allRounds.push(details1); - allRounds.push(details2); - allRounds.push(details3); - - - fundingRounds[++roundCounter] = details1; - fundingRounds[++roundCounter] = details2; - fundingRounds[++roundCounter] = details3; - } - - function addRound(uint256 amount, uint256 round) public { - roundCounter++; - fundingRounds[roundCounter] = FundingRoundDetails(amount, FundingRounds(round)); - - userRounds[msg.sender] = FundingRoundDetails(amount, FundingRounds(round)); - - } - - function getMyRoundInfo() public view returns(FundingRoundDetails memory) { - return userRounds[msg.sender]; - } - - function getRequiredFundingForRound(uint256 _roundNumber) public view returns(uint256){ - return allRounds[_roundNumber].fundingRequired; - } -} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/SolidityTest3.sol b/step03_solidity_tutorial/contracts/SolidityTest3.sol deleted file mode 100644 index 4746805..0000000 --- a/step03_solidity_tutorial/contracts/SolidityTest3.sol +++ /dev/null @@ -1,26 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract SolidityTest3 { - - - uint256 amount = 1 ether; - uint256 amount1 = 1_000_000_000_000_000_000; - uint256 amount2 = 1e18; - uint256 amount3 = 5_600_000_000_000_000_000; - - uint256 time = 24 hours; - uint256 week = 7 days; - - function applyConversion() public pure returns(uint256){ - //uint256 a = 45; - //uint8 b = uint8(a); - int8 a = -3; - uint8 b = uint8(a); - - return b; - - } -} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/SolidityTest4.sol b/step03_solidity_tutorial/contracts/SolidityTest4.sol deleted file mode 100644 index f3f4b46..0000000 --- a/step03_solidity_tutorial/contracts/SolidityTest4.sol +++ /dev/null @@ -1,56 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract SolidityTest4 { - - uint256 public counter; - address public treasureAddress; - address public owner; - uint256 public price = 0.01 ether; - - constructor() { - owner = msg.sender; - } - - modifier onlyOwner() { - require(msg.sender == owner, "Only Owner Can call"); - _; - } - - modifier verifyAmount(uint256 _amount) { - require(price == _amount, "Incorrect value provided"); - _; - } - - function updateAmount(uint256 _value) public verifyAmount(_value) { - price = _value; - counter++; - } - - function updateTreasureAddress(address _treasury) public onlyOwner { - treasureAddress = _treasury; - } - - - function doSomething() public view returns(uint256) { - return counter; - } - - function checkPureFunction(uint256 val) public pure returns(uint256) { - return val * 23; - } - - function multiVal() public view returns(uint256, bool) { - return (counter, false); - } - - function multiVal2() public view returns(uint256 index, bool isPaid) { - index = 4 * counter; - isPaid = true; - //// - //// - } - -} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/SolidityTest5.sol b/step03_solidity_tutorial/contracts/SolidityTest5.sol deleted file mode 100644 index 7cac5fe..0000000 --- a/step03_solidity_tutorial/contracts/SolidityTest5.sol +++ /dev/null @@ -1,39 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract SolidityTest5 { - - uint256 public countReceive; - uint256 public countFallback; - - mapping(address => uint256) public receiveBalance; - mapping(address => uint256) public fallbackBalance; - - function addSome() public { - countReceive+=20; - countFallback+=20; - } -/* - receive () external payable { - countReceive++; - receiveBalance[msg.sender]+= msg.value; - } - - fallback() external { - countFallback++; - //fallbackBalance[msg.sender] += msg.value; - } -*/ -} - - -contract SolidityTest6 { - - function testFunctionCall(address _contractAddress, string memory _signature) public { - (bool success,) = _contractAddress.call(abi.encodeWithSignature(_signature)); - require(success); - } - -} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/SolidityTest6.sol b/step03_solidity_tutorial/contracts/SolidityTest6.sol deleted file mode 100644 index ca260b6..0000000 --- a/step03_solidity_tutorial/contracts/SolidityTest6.sol +++ /dev/null @@ -1,75 +0,0 @@ -//SPDX-License-Identifier: Unlicense -pragma solidity ^0.8.0; - -import "hardhat/console.sol"; - -contract SolidityTest7 { - - function add1(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - uint256 max = 2 ** 256 - 1; - - return (max + max) % c; - } - - function add2(uint256 a, uint256 b, uint256 c) public pure returns (uint256) { - uint256 max = 2 ** 256 - 1; - return addmod(max, max, c); - } - - address payable public richest; - uint public mostSent; - mapping(address => uint256) pendingWithdrawals; - - constructor() { - richest = payable(msg.sender); - } - - function setAddress(address _add) public { - richest = payable(_add); - } - - /* - function becomeRichest() public payable returns (bool) { - if (msg.value > mostSent) { - // Insecure practice - richest.transfer(msg.value); - richest = payable(msg.sender); - mostSent = msg.value; - return true; - } else { - return false; - } - } - */ - - function becomeRichest() public payable returns (bool) { - if (msg.value > mostSent) { - pendingWithdrawals[richest] += msg.value; - richest = payable(msg.sender); - mostSent = msg.value; - return true; - } else { - return false; - } - } - function withdraw() public { - uint amount = pendingWithdrawals[msg.sender]; - pendingWithdrawals[msg.sender] = 0; - payable(msg.sender).transfer(amount); - //payable(msg.sender).call{value: amount, gas: 250000}(""); - } - -} - -contract DemoTest { - function testValue () public { - - } - - function getFunds (address addressOfContract) public { - SolidityTest7 abc = SolidityTest7(addressOfContract); - abc.withdraw(); - } - -} - diff --git a/step03_solidity_tutorial/contracts/Types.sol b/step03_solidity_tutorial/contracts/Types.sol new file mode 100644 index 0000000..4b0bd3d --- /dev/null +++ b/step03_solidity_tutorial/contracts/Types.sol @@ -0,0 +1,38 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract VarTypes { + + //1. fixed-size types + bool public isReady; //the value of boolean will be true/false + + //Signed and unsigned integers of varying sizes. + int public a = 2; //Signed int from 8 bits to 256 bits. int256 is the same as int we can sign negative value. + uint public b = 4; // Unsigned int from 8 bits to 256 bits. uint256 is the same as uint, we can't sign negative value. + + address public recipent; //we use address type for contract address + bytes32 public data;// This is intermediatory type More preferred way is to use byte types instead of String as string operation requires more gas as compared to byte operation. + + //2. variable-size types + string public name; //string for character but we use bytes instead of string + bytes public _data; // generalization of bytes type + uint[] public amounts; // array for uint types but we can't assign string into it. + mapping(uint => string) public users; //This is very similar as javascript object + + struct User { + uint id; + string name; + uint[] friendIds; + } + enum Color { + RED, + GREEN, + BLUE + } + //This is the high level overview of variable type in solidity but we will see all of these in detail in the next few tutorial + + +} + diff --git a/step03_solidity_tutorial/contracts/enum.sol b/step03_solidity_tutorial/contracts/enum.sol new file mode 100644 index 0000000..b10a757 --- /dev/null +++ b/step03_solidity_tutorial/contracts/enum.sol @@ -0,0 +1,52 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; +/* +Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums. + +With the use of enums it is possible to reduce the number of bugs in your code. +*/ +contract Enum { + enum OrderStatus { + gettingReady, + onYourWay, + delivered + } + + OrderStatus status = OrderStatus.gettingReady; + + function getStatus()public view returns(OrderStatus) { + //This function is return the status of our order now it is 0 + return status; + } + + function updateOrderStatus(OrderStatus _status ) public { + // here we take argument _status with type of OrderStatus so whenever we pass argument which is not in the status so this will return error + //There is another way of doing this we will look inthe next senario which is define bellow + //This function is return the updated status of our order . + status = _status; + } + function verifyOrderStatus() public view returns(bool ) { + //This function will verify first than return the status of our order now it is 0 + return status == OrderStatus.delivered; + } + + enum FundingR { + SEED, + PRIVATE, + PUBLIC + } + FundingR Cround = FundingR.SEED; + function gerCFR()public view returns (FundingR) { + return Cround; + } + function changeR(FundingR _round)public { + //This is the another way + require(_round == FundingR.SEED || _round == FundingR.PUBLIC || _round == FundingR.PRIVATE, "Invalid Round Information"); + Cround = FundingR(_round); + + } + +} + diff --git a/step03_solidity_tutorial/contracts/fallback_recieve_func.sol b/step03_solidity_tutorial/contracts/fallback_recieve_func.sol new file mode 100644 index 0000000..0891f96 --- /dev/null +++ b/step03_solidity_tutorial/contracts/fallback_recieve_func.sol @@ -0,0 +1,60 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract ReceiveFallback { + + uint256 public countReceive; + uint256 public countFallback; + + + mapping(address => uint256) public receiveBalance; + mapping(address => uint256) public fallbackBalance; + function addSome() public { + countReceive+=20; + countFallback+=20; + + } +/* +Fallback: +The fallback function now has a different syntax, declared using fallback() external [payable] {…} (without the function keyword). +This function cannot have arguments,cannot return anything and must have external visibility. The fallback function always receives data, + but to also receive Ether, you should mark it as payable. + +typically used the fallback function to handle logic in two scenarios: + +contract received ether and no data +contract received data but no function matched the function called + +Receive : +Receive is function same as fallback we use it when Contract Receives ethers but no data + + + */ + + receive () external payable { + countReceive++; + receiveBalance[msg.sender] += msg.value; + } + + + + fallback () external payable { + countFallback++; + fallbackBalance[msg.sender] += msg.value; + + } + + +} + +contract ReceiveFallback2 { + + + function testFunctioncall(address _contractAddress, string memory _signature) public { + (bool success,) = _contractAddress.call(abi.encodeWithSignature((_signature))); + require(success); + } +} + diff --git a/step03_solidity_tutorial/contracts/functionVisibility.sol b/step03_solidity_tutorial/contracts/functionVisibility.sol new file mode 100644 index 0000000..e95187e --- /dev/null +++ b/step03_solidity_tutorial/contracts/functionVisibility.sol @@ -0,0 +1,53 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract FunctionVisiblity1 { + //Function visibility allow us to who can access this function + // 1. Private + // 2. Public + // 3. External + + // Private + // we can only call function inside the contract it good to define private function with _ it's good but solidity doen't care of that + uint public value; + string public Name = "tariq"; + function _getValue() private view returns(uint) { + return value; + } + + //Internal + // we can access internal function inside the contract and the contract whcih is inherited from this contract but still can don't access function externaly + function getName() internal view returns(string storage) { + return Name; + } + //3. External + // we can only access outside the contract + function getValue() external view returns(uint) { + return value; + } + //4. Public we can acsees public funtion from inside the contract , from the contract which is inherited and also we can access it externaly + function setName(string memory _name) public { + Name = _name; + } +} + + + +contract FunctionVisiblity2 is FunctionVisiblity1 { + address public demo1Address;//we create this variable of storing address of new contract + + function AccessValue() public returns(string memory) { + + + //_getValue(); // we can't access private variable even this contract is inheritant from Demo1 + string memory newName =getName(); // we can access Internal function inside the inherit contract + // getValue(); //we can't access external function inside the contract and also the contract which is inherited from this contract + setName("Jokhio"); // here we can acces + return newName; + } + + + +} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/loop.sol b/step03_solidity_tutorial/contracts/loop.sol new file mode 100644 index 0000000..aa8c341 --- /dev/null +++ b/step03_solidity_tutorial/contracts/loop.sol @@ -0,0 +1,47 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; +// public private Variable Scope +contract Loop { + + uint256 data = 1; + + function forloop() public { + + for (uint256 i; i<10; i++){ + data = data*2; + if (data >500){ + console.log(data); + continue; + } + } + } + + + function whileloop() public { + + uint age = data; + + + while(data<1000){ + age = data++; + console.log(age); // print sequence from 1 to 999 after 1000 loop will finish + } + } + + + + + function doWhile()public { + uint age ; + do{ + + data++; + age = data*2; + console.log("age", age); + } + while(data<10); + } + +} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/math.sol b/step03_solidity_tutorial/contracts/math.sol new file mode 100644 index 0000000..43c94c0 --- /dev/null +++ b/step03_solidity_tutorial/contracts/math.sol @@ -0,0 +1,39 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; +/* +Solidity provides inbuilt mathematical functions as well. Following are heavily used methods − + +1. addmod(uint x, uint y, uint k) returns (uint) − computes (x + y) % k where the addition is performed with arbitrary precision and does not wrap around at 2256. +2. mulmod(uint x, uint y, uint k) returns (uint) − computes (x * y) % k where the addition is performed with arbitrary precision and does not wrap around at 2256. +*/ + +contract Math { + + function add1(uint256 a) public pure returns(uint){ + /* + This is our addmod function the basic difference between our custom of solidity builtin function + is our function wrap big number around at 2^256.but solidity buildin function does not wrap around at 2^256. + */ + uint256 max = 2 ** 256 -1; + return(max + max) % a; + + } + function add2(uint256 a) public pure returns(uint){ + uint256 max = 2 ** 256 -1; + return(max * max) % a; + + } + + function callAddMod(uint256 a) public pure returns(uint){ + uint256 max = 2 ** 256 -1; + return addmod(max, max, a); + } + function callMulMod(uint a) public pure returns(uint){ + uint256 max = 2 ** 256 -1; + return mulmod(max, max, a); + } + +} + diff --git a/step03_solidity_tutorial/contracts/modifier.sol b/step03_solidity_tutorial/contracts/modifier.sol new file mode 100644 index 0000000..6513f36 --- /dev/null +++ b/step03_solidity_tutorial/contracts/modifier.sol @@ -0,0 +1,32 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + + + + +contract Modifier { + + //Function Modifiers are used to modify the behaviour of a function. + // For example to add a prerequisite to a function. + + uint public counter; + address public treasureAddress; + address public owner; + constructor() { + owner = msg.sender; + } + + modifier onlyOwner() { + //this modifier check wheather the caller of the fuction is Owner or not + // if the caller of the function is the owner of the contract this will allow us to call the particular function where we use this modifier + require(msg.sender == owner, "ONly Owner Can Call" ); + _; + } + + function updateTreasureAddress(address _treasure) public onlyOwner { + treasureAddress = _treasure; + } + +} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/overload.sol b/step03_solidity_tutorial/contracts/overload.sol new file mode 100644 index 0000000..806776b --- /dev/null +++ b/step03_solidity_tutorial/contracts/overload.sol @@ -0,0 +1,35 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract Overload { + /* + You can have multiple definitions for the same function name in the same scope. The definition of the + function must differ from each other by the types and/or the number of arguments in the argument list. + You cannot overload function declarations that differ only by return type. + */ + + function getSum(uint a, uint b) public pure returns(uint){ + return a + b; + } + function getSum(uint a, uint b, uint c) public pure returns(uint){ + return a + b + c; + } + function getSum(uint256 a, bool b) public pure returns(uint){ + return a ; + } + function getSum( bool b, uint256 a) public pure returns(uint){ + return a ; + } + + function callSumWithTwoArguments() public pure returns(uint){ + return getSum(1,2); + } + function callSumWithThreeArguments() public pure returns(uint){ + return getSum(1,2,3); + } + + +} + diff --git a/step03_solidity_tutorial/contracts/string.sol b/step03_solidity_tutorial/contracts/string.sol new file mode 100644 index 0000000..d0e2157 --- /dev/null +++ b/step03_solidity_tutorial/contracts/string.sol @@ -0,0 +1,32 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; +// public private Variable Scope +contract String { + + + + function getName() public pure returns(string memory) { + string memory firstName = "Tariq"; + string memory lastName = "Nawaz"; + + string memory name; + + name = string(abi.encodePacked(firstName,lastName)); + // string memory FullName = string(abi.encodePacked(fastName,lastName)); + // bytes memory byteName = bytes(FullName); + // string memory strName = string(byteName); + return name; + + } + function getBytesName(string memory firstName, string memory lastName)public pure returns( bytes memory ) { + string memory FullName = string(abi.encodePacked(firstName,lastName)); + bytes memory byteName = bytes(FullName); + // string memory strName = string(byteName); + return (byteName); + } + + +} + \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/struct.sol b/step03_solidity_tutorial/contracts/struct.sol new file mode 100644 index 0000000..5527e9d --- /dev/null +++ b/step03_solidity_tutorial/contracts/struct.sol @@ -0,0 +1,96 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + + + + +contract Struct { + enum FundingRounds { + SEED, + PRIVATE, + PUBLIC + } + + struct FundingRoundDetails{ + uint256 funding; + FundingRounds round; + } + FundingRoundDetails[] public allRounds; + + function addFundingR()public { + FundingRoundDetails memory details1 = FundingRoundDetails(1000,FundingRounds.SEED); + FundingRoundDetails memory details2 = FundingRoundDetails(2000,FundingRounds.SEED); + FundingRoundDetails memory details3 = FundingRoundDetails(3000,FundingRounds.SEED); + allRounds.push(details1); + allRounds.push(details2); + allRounds.push(details3); + } + + function getFundingR(uint256 _round) public view returns (uint256) { + return allRounds[_round].funding; + } + + + //struct inside mapping + mapping(uint256 => FundingRoundDetails) private fundingRounds; + uint256 public roundCounter; + mapping(address => FundingRoundDetails) private userRounds; + + function addRound(uint256 _amount, uint256 _round)public { + roundCounter++; + fundingRounds[roundCounter] = FundingRoundDetails(_amount, FundingRounds(_round)); + + userRounds[msg.sender] = FundingRoundDetails(_amount, FundingRounds(_round)); + } + function getFunding(uint _roundNumber) public view returns(uint256) { + return fundingRounds[_roundNumber].funding; + } + function getMyRoundInfo(uint256 _round) public view returns(FundingRoundDetails memory ){ + return fundingRounds[_round]; + } + function senderRoundInfo()public view returns(FundingRoundDetails memory) { + return userRounds[msg.sender]; + } + + + //now combination of stuck, mapping + //first mapping inside struct + struct UserInfo { + string name; + uint256 age; + mapping(address => uint256) fundingReceived; + } + + mapping(address =>UserInfo) public users; + function addUser() public { + // UserInfo memory _user = UserInfo("Zia KHan, 30) + UserInfo storage _user = users[msg.sender]; + + _user.name = "Tariq"; + _user.age = 32; + } + + function provideFunding(uint256 _amount,address _user)public returns(uint256) { + UserInfo storage _userInfo = users[_user]; + _userInfo.fundingReceived[msg.sender] = _amount; + _userInfo.fundingReceived[msg.sender] = 2; + return _userInfo.fundingReceived[msg.sender]; + } + + //mapping inside mapping + // enum RollInSchool{ + // STUDENT, + // TEACHER + // } + // mapping(uint=> mapping(string=>RollInSchool)) roll; + + // function addRoll(uint _index, string memory _name, RollInSchool _roll)public { + // roll[_index][_name]= _roll; + + // } + + + +} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/variables.sol b/step03_solidity_tutorial/contracts/variables.sol new file mode 100644 index 0000000..6b0e984 --- /dev/null +++ b/step03_solidity_tutorial/contracts/variables.sol @@ -0,0 +1,40 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; +contract VarVisibility1 { + // 1. Private Variable + uint256 private age; //this is only call by this contract + // 1. Internal Variable + //Internal variable can be call by this contract and the contract which is inherited by this contract + uint256 internal height; + // 3. Public + // Public variable can be called by anyone + string public Name = "tariq jokhio"; // by default this is state level variable + + function updateAge(uint _age) public { + age = _age; + height = 6; + + } +} + + +contract Variable is VarVisibility1 { + //Types of Variable + + //1. State Variables − Variables whose values are permanently stored in a contract storage. + + //2. Local Variables − Variables whose values are present till function is executing. + + //3. Global Variables − Special variables exists in the global namespace used to get information about the blockchain. + //one example of Global variable is msg.sender (address payable) + + function updateHeight(uint _height) public { + //height = _height / age; //Solidity doesn't allow us to call private variable + height = _height; + } + function getName() public view returns(string memory) { + return Name; + } +} \ No newline at end of file diff --git a/step03_solidity_tutorial/contracts/view_pure_funciton.sol b/step03_solidity_tutorial/contracts/view_pure_funciton.sol new file mode 100644 index 0000000..c4c4f1d --- /dev/null +++ b/step03_solidity_tutorial/contracts/view_pure_funciton.sol @@ -0,0 +1,33 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract Practice { + //1. view: when we use view the solidity use eth_call + //2. pure: when we use pure the solidity use eth_call + //3. When we don't use view or pure the solidity use eth_sendTrasaction + + uint value; + + function getValue() external view returns(uint){ + //View keyword is for read only means we cann't change value of state variable and we cann't perform any computation. + // value = 3;// if we are trying to change state varaible but we couldn't this will give us error. + return value; + } + function setValue() external returns(uint){ + //we can change value of state variable or modifie the blockchain without defining the view and pure + value = value + 3; + return value; + } + + function getValue1() external pure returns(uint){ + // instant of just return the value from bockchain. it will just do some computation + uint value1; + + return value1 +1; + } + + +} + diff --git a/step03_solidity_tutorial/contracts/withdrawalPattern.sol b/step03_solidity_tutorial/contracts/withdrawalPattern.sol new file mode 100644 index 0000000..06d7dd9 --- /dev/null +++ b/step03_solidity_tutorial/contracts/withdrawalPattern.sol @@ -0,0 +1,53 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +import "hardhat/console.sol"; + +contract WithDrawal { + address payable public richest; + uint public mostSent; + mapping(address => uint) public pendingWithDrawals; + constructor(){ + richest = payable(msg.sender); + } + + function setAddress( address _add) public { + richest = payable(_add); + } + + function becomeRichest() public payable returns(bool ){ + if (msg.value > mostSent){ + pendingWithDrawals[richest] += msg.value; + richest = payable(msg.sender); + mostSent = msg.value; + return true; + } + else{ + return false; + + } + } + function withDraw() public{ + uint amount = pendingWithDrawals[msg.sender]; + pendingWithDrawals[msg.sender] = 0; + payable(msg.sender).transfer(amount); + } + + +} + +contract Demo { + function testValue () public { + + } + + function getFunds(address _contractAddress) public { + WithDrawal abc = WithDrawal(_contractAddress); + abc.withDraw(); + + } + receive() external payable { + + } +} + diff --git a/step03_solidity_tutorial/scripts/Demo.ts b/step03_solidity_tutorial/scripts/Demo.ts new file mode 100644 index 0000000..9f11a55 --- /dev/null +++ b/step03_solidity_tutorial/scripts/Demo.ts @@ -0,0 +1,31 @@ +import { ethers } from "hardhat"; +import { Demo2, Demo2__factory, Overload__factory } from "../typechain"; +import { SolidityTest__factory } from "../typechain/factories/SolidityTest__factory"; + +async function main() { + + const Contract: Demo2__factory = await ethers.getContractFactory("Demo2"); + const contract:Demo2 = await Contract.deploy(); + + await contract.deployed(); + + console.log("Address of deployed contract Demo2 is :", contract.address); + const txt1 =await contract.createExample("First"); + const demoAddress1 = await contract.demo1Address(); + console.log("Address of First Instanse of demo1 is ",demoAddress1); + const txt2 =await contract.createExample("Second"); + const demoAddress2 = await contract.demo1Address(); + console.log("Address of Second Instanse of demo1 is ",demoAddress2); + const txt3 =await contract.createExample("Third"); + const demoAddress3 =await contract.demo1Address(); + console.log("Address of Third Instanse of demo1 is ",demoAddress3); + + const name = await contract.getNameOfContract(demoAddress3); + console.log("Name of given address is " , name); + + +} +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/step03_solidity_tutorial/scripts/deploy-prac-contract.ts b/step03_solidity_tutorial/scripts/deploy-prac-contract.ts new file mode 100644 index 0000000..3a56924 --- /dev/null +++ b/step03_solidity_tutorial/scripts/deploy-prac-contract.ts @@ -0,0 +1,29 @@ +import { ethers } from "hardhat"; +import { Practice, Practice__factory } from "../typechain"; +import { SolidityTest__factory } from "../typechain/factories/SolidityTest__factory"; + +async function main() { + + const PracticeSolidity: Practice__factory = await ethers.getContractFactory("Practice"); + const practiceSolidity:Practice = await PracticeSolidity.deploy(); + + await practiceSolidity.deployed(); + + console.log("Greeter deployed to:", practiceSolidity.address); + + const data = await practiceSolidity.age(); + console.log("data of age is ", data.toString()); + + const trans = await practiceSolidity.updateAge(); + trans.wait(); + console.log('update Done'); + const data1 = await practiceSolidity.age(); + console.log("data of age is ", data1.toString()); + + + +} +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/step03_solidity_tutorial/scripts/deploy.ts b/step03_solidity_tutorial/scripts/deploy.ts deleted file mode 100644 index 26a0e3a..0000000 --- a/step03_solidity_tutorial/scripts/deploy.ts +++ /dev/null @@ -1,256 +0,0 @@ -import { BigNumber } from "ethers"; -import { ethers } from "hardhat"; -import { SolidityTest, SolidityTest2, SolidityTest2__factory, SolidityTest3, SolidityTest3__factory, SolidityTest__factory } from "../typechain"; -import { Demo1 } from "../typechain/Demo1"; -import { Demo2 } from "../typechain/Demo2"; -import { DemoTest } from "../typechain/DemoTest"; -import { Demo1__factory } from "../typechain/factories/Demo1__factory"; -import { Demo2__factory } from "../typechain/factories/Demo2__factory"; -import { DemoTest__factory } from "../typechain/factories/DemoTest__factory"; -import { SolidityTest4__factory } from "../typechain/factories/SolidityTest4__factory"; -import { SolidityTest5__factory } from "../typechain/factories/SolidityTest5__factory"; -import { SolidityTest6__factory } from "../typechain/factories/SolidityTest6__factory"; -import { SolidityTest7__factory } from "../typechain/factories/SolidityTest7__factory"; -import { SolidityTest4 } from "../typechain/SolidityTest4"; -import { SolidityTest5 } from "../typechain/SolidityTest5"; -import { SolidityTest6 } from "../typechain/SolidityTest6"; -import { SolidityTest7 } from "../typechain/SolidityTest7"; - -async function main() { - - const [owner, addr1, addr2] = await ethers.getSigners(); - - const Demo2:Demo2__factory = await ethers.getContractFactory("Demo2"); - const demo2:Demo2 = await Demo2.deploy(); - - await demo2.deployed(); - console.log("Demo2 deployed to:", demo2.address); - - const txt1 = await demo2.createExample("First"); - const demoAddress1 = await demo2.demo1Address(); - console.log("Demo 1 Address = ",demoAddress1); - - const txt2 = await demo2.createExample("Second"); - const demoAddress2 = await demo2.demo1Address(); - console.log("Demo 1 Address = ",demoAddress2); - - - const txt3 = await demo2.createExample("Third"); - const demoAddress3 = await demo2.demo1Address(); - console.log("Demo 1 Address = ",demoAddress3); - - - const name = await demo2.getNameOfContract(demoAddress2); - console.log("Name = ",name); - - /* - const Demo1:Demo1__factory = await ethers.getContractFactory("Demo1"); - const demo1:Demo1 = await Demo1.attach(demoAddress2); - - console.log("Demo1 deployed to:", demo1.address); - - const name = await demo1.getName(); - console.log("Name = ",name); - */ - - - - - - - /* - const SolidityTest7:SolidityTest7__factory = await ethers.getContractFactory("SolidityTest7"); - const solidtyTest7:SolidityTest7 = await SolidityTest7.deploy(); - - await solidtyTest7.deployed(); - console.log("SolidityTest6 deployed to:", solidtyTest7.address); - - const DemoTest:DemoTest__factory = await ethers.getContractFactory("DemoTest"); - const demoTest:DemoTest = await DemoTest.deploy(); - - await demoTest.deployed(); - console.log("demoTest deployed to:", demoTest.address); - - await solidtyTest7.setAddress(demoTest.address); - - - const txt1 = await solidtyTest7.connect(addr2).becomeRichest({value: ethers.utils.parseEther("1")}); - - */ - - - - - //console.log("Add 1 = ", (await solidtyTest7.add1(23,45,6)).toString()); - //console.log("Add 2 = ", (await solidtyTest7.add2(23,45,1)).toString()); - - - /* - console.log("Sub ", (await solidtyTest7["getSum(uint256,uint256)"](34,45)).toString()); - console.log("Sub ", (await solidtyTest7["getSum(uint256,uint256,uint256)"](34,45, 67)).toString()); - */ - /* - const SolidityTest5:SolidityTest5__factory = await ethers.getContractFactory("SolidityTest5"); - const solidtyTest5:SolidityTest5 = await SolidityTest5.deploy(); - - await solidtyTest5.deployed(); - console.log("SolidityTest5 deployed to:", solidtyTest5.address); - - const SolidityTest6:SolidityTest6__factory = await ethers.getContractFactory("SolidityTest6"); - const solidtyTest6:SolidityTest6 = await SolidityTest6.deploy(); - - await solidtyTest6.deployed(); - - console.log("SolidityTest6 deployed to:", solidtyTest6.address); - - console.log("Balance of Contract = ", (await ethers.provider.getBalance(solidtyTest5.address)).toString()); - - console.log("Receive Coutner = ", (await solidtyTest5.countReceive()).toString()); - console.log("Fallback Coutner = ", (await solidtyTest5.countFallback()).toString()); - - console.log("Receive Balance = ", (await solidtyTest5.receiveBalance(addr1.address)).toString()) - console.log("Fallback Balance = ", (await solidtyTest5.fallbackBalance(addr1.address)).toString()); - - //const txt1 = await solidtyTest6.testFunctionCall(solidtyTest5.address, "hellWorld()"); - - - - const txt1 = await addr1.sendTransaction({ - to: solidtyTest5.address, - value: ethers.utils.parseEther("1"), - }); - - - console.log("After ======>"); - console.log("Balance of Contract = ", (await ethers.provider.getBalance(solidtyTest5.address)).toString()); - - console.log("Receive Coutner = ", (await solidtyTest5.countReceive()).toString()); - console.log("Fallback Coutner = ", (await solidtyTest5.countFallback()).toString()); - - console.log("Receive Balance = ", (await solidtyTest5.receiveBalance(addr1.address)).toString()) - console.log("Fallback Balance = ", (await solidtyTest5.fallbackBalance(addr1.address)).toString()); - - */ - - - - - - /* - const SolidityTest4:SolidityTest4__factory = await ethers.getContractFactory("SolidityTest4"); - const solidtyTest4:SolidityTest4 = await SolidityTest4.deploy(); - - await solidtyTest4.deployed(); - - console.log("SolidityTest4 deployed to:", solidtyTest4.address); - - console.log("Owner address = ", owner.address); - - - console.log("Counter before = ", (await solidtyTest4.counter()).toString()); - - const txt1 = await solidtyTest4.updateAmount(ethers.utils.parseEther("0.001")); - - console.log("Counter after = ", (await solidtyTest4.counter()).toString()); - */ - - //console.log("contract owner address = ", await solidtyTest4.owner()); - //console.log("treasure address = ", await solidtyTest4.treasureAddress()); - - /* - console.log("contract owner address = ", await solidtyTest4.owner()); - console.log("treasure address = ", await solidtyTest4.treasureAddress()); - - //const txt1 = await solidtyTest4.updateTreasureAddress(addr1.address); - - const txt1 = await solidtyTest4.connect(addr2).updateTreasureAddress(addr1.address); - - console.log("contract owner address = ", await solidtyTest4.owner()); - console.log("treasure address = ", await solidtyTest4.treasureAddress()); - */ - - /* - const val = await solidtyTest4.doSomething(); - const val2 = await solidtyTest4.checkPureFunction(10); - console.log("value = ",val.toString()); - console.log("value 2 = ",val2.toString()); - - const val3 = await solidtyTest4.multiVal(); - console.log("value 3 = ",val3); - console.log("value 3 = ",val3[0]); - console.log("value 3 = ",val3[1]); - - const val4 = await solidtyTest4.multiVal(); - console.log("value 4 = ",val4); - console.log("value 4 = ",val4[0]); - console.log("value 4 = ",val4[1]); - */ - - /* - const SolidityTest3:SolidityTest3__factory = await ethers.getContractFactory("SolidityTest3"); - const solidtyTest3:SolidityTest3 = await SolidityTest3.deploy(); - - await solidtyTest3.deployed(); - - console.log("SolidityTest3 deployed to:", solidtyTest3.address); - - console.log("value = ",(await solidtyTest3.applyConversion()).toString()); - */ - - /* - const etherValue = await ethers.utils.parseEther("5.6"); - console.log("Ehter value = ",etherValue.toString()); - - const num = BigNumber.from("100000000000000000000"); - console.log("Ehter value = ",await ethers.utils.formatEther(num)); - */ - - /* - const SolidityTest2:SolidityTest2__factory = await ethers.getContractFactory("SolidityTest2"); - const solidtyTest2:SolidityTest2 = await SolidityTest2.deploy(); - - await solidtyTest2.deployed(); - - console.log("SolidityTest2 deployed to:", solidtyTest2.address); - - await solidtyTest2.addFundingRounds(); - - const roundInfo = await solidtyTest2.allRounds(2) - console.log(roundInfo); - console.log("fundingRequired = ",roundInfo.fundingRequired.toString()); - console.log("round = ",roundInfo.round); - */ - /* - const SolidityTest:SolidityTest__factory = await ethers.getContractFactory("SolidityTest"); - const solidtyTest:SolidityTest = await SolidityTest.deploy(); - - await solidtyTest.deployed(); - - console.log("SolidityTest2 deployed to:", solidtyTest.address); - - console.log("Current Round = ", await solidtyTest.getCurrentFundingRound()); - - await solidtyTest.changeRound(5); - - console.log("Current Round After = ", await solidtyTest.getCurrentFundingRound()); - */ - - /* - console.log("Juice = ", await solidtyTest.getJuice()); - - console.log("is Juice Extra Large = ", await solidtyTest.verifyJuiceSize()); - - await solidtyTest.updateJuiceSize(3); - - console.log("Juice = ", await solidtyTest.getJuice()); - console.log("is Juice Extra Large after = ", await solidtyTest.verifyJuiceSize()); - */ - -} - -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. -main().catch((error) => { - console.error(error); - process.exitCode = 1; -}); diff --git a/step03_solidity_tutorial/scripts/enum.ts b/step03_solidity_tutorial/scripts/enum.ts new file mode 100644 index 0000000..4fc179d --- /dev/null +++ b/step03_solidity_tutorial/scripts/enum.ts @@ -0,0 +1,39 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node