├── .gitignore ├── CallFromContract.sol ├── CarFactory.sol ├── CryptoLeekNFT.sol ├── ERC1155.sol ├── ERC20.sol ├── Error.sol ├── EtherUnits.sol ├── Event.sol ├── Fallback.sol ├── FunctionVisibility.sol ├── GlobalVariables.sol ├── Import.sol ├── Inheritance.sol ├── Interface.sol ├── LICENSE ├── Library.sol ├── Mapping.sol ├── Modifer.sol ├── MultiInheritance.sol ├── README.md ├── StringUtils.sol ├── Struct.sol ├── UniswapExample.sol ├── Wallet.sol ├── myLibs └── Car.sol └── notes.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /CallFromContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract ContractA { 5 | uint public x; 6 | uint public value; 7 | 8 | function setX(uint _x) public returns (uint) { 9 | x = _x; 10 | return x; 11 | } 12 | 13 | function setXandSendEther(uint _x) public payable returns (uint, uint) { 14 | x = _x; 15 | value = msg.value; 16 | return (x, value); 17 | } 18 | 19 | function getBalance() public view returns (uint) { 20 | return address(this).balance; 21 | } 22 | } 23 | 24 | // ContractB -> ContractA 25 | contract ContractB { 26 | 27 | function callSetX(ContractA _contractA, uint _x) public { 28 | _contractA.setX(_x); 29 | } 30 | 31 | function callSetXFromAddress(address _contractAAddres, uint _x) public { 32 | ContractA _contractA = ContractA(_contractAAddres); 33 | _contractA.setX(_x); 34 | } 35 | 36 | function callSetXandSendEther(ContractA _contractA, uint _x) public payable { 37 | _contractA.setXandSendEther{value: msg.value}(_x); 38 | } 39 | 40 | function getBalance() public view returns (uint) { 41 | return address(this).balance; 42 | } 43 | } -------------------------------------------------------------------------------- /CarFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Car { 5 | string public model; 6 | address public owner; 7 | uint public cost; 8 | 9 | constructor(string memory _model, address _owner) payable { 10 | model = _model; 11 | owner = _owner; 12 | cost = msg.value; 13 | } 14 | 15 | 16 | } 17 | 18 | contract CarFactory { 19 | Car[] public cars; 20 | 21 | // function create(string memory _model) public { 22 | // Car car = new Car(_model, address(this)); 23 | // cars.push(car); 24 | // } 25 | 26 | // 0x447Ec763df0A9806e33130d9695a5c0a5DAe9e76 27 | // 0x978a01431F9bF1d7750DE1b0b0Bd48445E8184F1 28 | 29 | function createWithMoney(string memory _model) public payable { 30 | 31 | require(msg.value >= 1 ether, "Not enough money"); 32 | 33 | Car car = new Car{value: msg.value}(_model, address(this)); 34 | cars.push(car); 35 | } 36 | } -------------------------------------------------------------------------------- /CryptoLeekNFT.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; 5 | 6 | contract CryptoLeekNFT is ERC721URIStorage { 7 | uint public counter; 8 | 9 | constructor() ERC721("CryptoLeekNFT", "CLN") { 10 | counter = 0; 11 | } 12 | 13 | function createNFTs (string memory tokenURI) public returns (uint) { 14 | uint tokenId = counter; 15 | 16 | _safeMint(msg.sender, tokenId); 17 | _setTokenURI(tokenId, tokenURI); 18 | 19 | counter ++; 20 | 21 | return tokenId; 22 | } 23 | 24 | function burn(uint tokenId) public virtual { 25 | require(_isApprovedOrOwner(msg.sender, tokenId), "You are not the owner or not approved@"); 26 | super._burn(tokenId); 27 | } 28 | } -------------------------------------------------------------------------------- /ERC1155.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol"; 5 | 6 | contract GameItems is ERC1155 { 7 | uint256 public constant GOLD = 0; 8 | uint256 public constant SILVER = 1; 9 | uint256 public constant THORS_HAMMER = 2; 10 | uint256 public constant SWORD = 3; 11 | uint256 public constant SHIELD = 4; 12 | 13 | constructor() public ERC1155("https://gateway.pinata.cloud/ipfs/QmaGvW4ynPfSUNg949mXdVezsaym9nb9e1QjvQ6EAr7x8L/{id}.json") { 14 | _mint(msg.sender, GOLD, 10**18, ""); 15 | _mint(msg.sender, SILVER, 10**27, ""); 16 | _mint(msg.sender, THORS_HAMMER, 1, ""); 17 | _mint(msg.sender, SWORD, 10**9, ""); 18 | _mint(msg.sender, SHIELD, 10**9, ""); 19 | } 20 | } -------------------------------------------------------------------------------- /ERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"; 5 | 6 | contract MyToken is ERC20 { 7 | constructor(string memory name, string memory symbol) ERC20(name, symbol) { 8 | _mint(msg.sender, 100 * 10 ** uint(decimals())); 9 | } 10 | } -------------------------------------------------------------------------------- /Error.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | // require 4 | // assert 5 | // revert 6 | 7 | pragma solidity ^0.8.4; 8 | 9 | contract Error { 10 | int public balance; 11 | 12 | function deposit(int _amount) public { 13 | //require(_amount > 0, "Deposited amount must be greater than zero"); 14 | int oldBalance = balance; 15 | balance += _amount; 16 | if (balance < oldBalance) { 17 | revert("Impossible!"); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /EtherUnits.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.4; 4 | 5 | contract EtherUnits { 6 | uint public oneWei = 1 wei; 7 | uint public oneGwei = 1 gwei; // 1 * 10 ** 9 8 | uint public oneEther = 1 ether; 9 | 10 | function testOneWei() public view returns(bool) { 11 | return oneWei == 1; 12 | } 13 | 14 | function testOneGwei() public view returns(bool) { 15 | return oneGwei == 1 * 10 ** 9 wei; 16 | } 17 | 18 | function testOneEther() public view returns(bool) { 19 | return oneEther == 1 * 10 ** 18 wei; 20 | } 21 | } -------------------------------------------------------------------------------- /Event.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.4; 4 | 5 | contract Event { 6 | event Log(address sender, string message); 7 | 8 | function transfer() public { 9 | // xxxxx 10 | emit Log(msg.sender, "I send 1 ether to you!"); 11 | emit Log(msg.sender, "I send 2 ether to you!"); 12 | emit Log(msg.sender, "I send 3 ether to you!"); 13 | } 14 | } -------------------------------------------------------------------------------- /Fallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Fallback { 5 | event Log(uint gas); 6 | 7 | 8 | fallback() external payable { 9 | emit Log(gasleft()); 10 | } 11 | 12 | function getBalance() public view returns (uint) { 13 | return address(this).balance; 14 | } 15 | } 16 | 17 | contract SendEther { 18 | 19 | function send(address payable _to) public payable { 20 | _to.transfer(msg.value); 21 | } 22 | 23 | function call(address payable _to) public payable { 24 | (bool sent,) = _to.call{value:msg.value}("hello world!"); 25 | require(sent); 26 | } 27 | } -------------------------------------------------------------------------------- /FunctionVisibility.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // private, internal, external, public 3 | 4 | pragma solidity ^0.8.4; 5 | 6 | contract FunctionVisibility { 7 | uint value; 8 | 9 | function getValue() external view returns (uint) { 10 | return _getValuePrivate(); 11 | } 12 | 13 | function setValue(uint _value) public { 14 | value = _value; 15 | } 16 | 17 | function _getValueInternal() internal view returns (uint) { 18 | return value; 19 | } 20 | 21 | function _getValuePrivate() private view returns (uint) { 22 | return value; 23 | } 24 | } 25 | 26 | contract SubFunctionVisibility is FunctionVisibility{ 27 | function getValueFromParent() public view returns(uint) { 28 | return _getValueInternal(); 29 | } 30 | } -------------------------------------------------------------------------------- /GlobalVariables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.4; 4 | 5 | contract GlobalVariables { 6 | event LOG(address, uint); 7 | 8 | function getGasInfo() public view returns (uint, uint) { 9 | return (tx.gasprice, block.gaslimit); 10 | } 11 | 12 | function getBlockInfo() public view returns (uint, address, uint, uint, uint, uint) { 13 | return (block.chainid, // current chain id 14 | block.coinbase, // current block miner’s address 15 | block.difficulty, // (uint): current block difficulty 16 | block.gaslimit, // (uint): current block gaslimit 17 | block.number, // (uint): current block number 18 | block.timestamp); // (uint) 19 | } 20 | 21 | function getMessageInfo() public payable { 22 | emit LOG(msg.sender, msg.value); 23 | } 24 | } -------------------------------------------------------------------------------- /Import.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | 5 | import "./myLibs/Car.sol"; 6 | 7 | contract CarFactory2 { 8 | Car[] public cars; 9 | 10 | // function create(string memory _model) public { 11 | // Car car = new Car(_model, address(this)); 12 | // cars.push(car); 13 | // } 14 | 15 | // 0x447Ec763df0A9806e33130d9695a5c0a5DAe9e76 16 | // 0x978a01431F9bF1d7750DE1b0b0Bd48445E8184F1 17 | 18 | function createWithMoney(string memory _model) public payable { 19 | 20 | require(msg.value >= 1 ether, "Not enough money"); 21 | 22 | Car car = new Car{value: msg.value}(_model, address(this)); 23 | cars.push(car); 24 | } 25 | } 26 | 27 | 28 | import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"; 29 | contract MyToken is ERC20 { 30 | // constructor() ERC20("cryptoleek.finance", "LEEK") { 31 | 32 | // } 33 | 34 | constructor(string memory name, string memory symbol) ERC20(name, symbol) { 35 | 36 | } 37 | 38 | function decimals() public pure override returns (uint8) { 39 | return 9; 40 | } 41 | } -------------------------------------------------------------------------------- /Inheritance.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.4; 4 | 5 | contract A { 6 | 7 | string public name; 8 | 9 | constructor(string memory _name) { 10 | name = _name; 11 | } 12 | 13 | function getContractName() public view virtual returns (string memory) { 14 | return name; 15 | } 16 | } 17 | 18 | contract B is A { 19 | string public helloworld; 20 | 21 | constructor(string memory _name, string memory _helloworld) A(_name) { 22 | helloworld = _helloworld; 23 | } 24 | } -------------------------------------------------------------------------------- /Interface.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Counter { 5 | uint public count; 6 | 7 | function increment() external { 8 | count ++; 9 | } 10 | } 11 | 12 | interface ICounter { 13 | function increment() external; 14 | } 15 | 16 | contract MyContract { 17 | 18 | function incrementCounter(address _counter) external { 19 | ICounter(_counter).increment(); 20 | } 21 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 CryptoLeek 币圈老韭菜 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Library.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | library SafeMath { 5 | function add(uint x, uint y) internal pure returns(uint) { 6 | uint result = x + y; 7 | require(result >= x, "Overflow!"); 8 | 9 | return result; 10 | } 11 | } 12 | 13 | contract TestSafeMath { 14 | using SafeMath for uint; 15 | 16 | function testAdd(uint x, uint y) public pure returns (uint) { 17 | uint result = x.add(y); 18 | //SafeMath.add(x, y); 19 | 20 | return result; 21 | } 22 | } 23 | 24 | library Array { 25 | function remove(uint[] storage arr, uint index) public { 26 | arr[index] = arr[arr.length -1]; 27 | arr.pop(); 28 | } 29 | } 30 | 31 | contract TestArray { 32 | using Array for uint[]; 33 | 34 | uint[] public testArr; 35 | 36 | function testArrayRemove() public { 37 | testArr.push(1); 38 | testArr.push(2); 39 | testArr.push(3); 40 | 41 | // [1,2,3] 42 | 43 | testArr.remove(1); 44 | 45 | // [1,3] 46 | 47 | assert(testArr.length == 2); 48 | assert(testArr[0] == 1); 49 | assert(testArr[1] == 3); 50 | } 51 | } -------------------------------------------------------------------------------- /Mapping.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Mapping { 5 | event LOG(address, uint); 6 | 7 | mapping(address => uint) public myMap; 8 | address[] public myMappingAddr; 9 | 10 | function setMapping(address _myAddr, uint _number) public { 11 | myMap[_myAddr] = _number; 12 | myMappingAddr.push(_myAddr); 13 | } 14 | 15 | function getMapping(address _myAddr) public view returns (uint) { 16 | return myMap[_myAddr]; 17 | } 18 | 19 | function deleteMapping(address _myAddr) public { 20 | delete myMap[_myAddr]; 21 | } 22 | 23 | function getTotal() public view returns (uint) { 24 | require(myMappingAddr.length > 0, "The mapping has no values!"); 25 | 26 | uint sum = 0; 27 | for (uint i = 0; i < myMappingAddr.length; i++) { 28 | address key = myMappingAddr[i]; 29 | uint value = myMap[key]; 30 | sum += value; 31 | } 32 | 33 | return sum; 34 | } 35 | 36 | function test () public { 37 | setMapping(0x5B38Da6a701c568545dCfcB03FcB875f56beddC4, 10); 38 | setMapping(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2, 20); 39 | setMapping(0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db, 30); 40 | 41 | uint sum = getTotal(); 42 | 43 | assert(sum == 60); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /Modifer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Modifer { 5 | 6 | address public owner; 7 | 8 | constructor() { 9 | owner = msg.sender; 10 | } 11 | 12 | modifier onlyOwner() { 13 | require(owner == msg.sender, "Not Owner"); 14 | _; 15 | } 16 | 17 | function onlyCallByOwner() public onlyOwner pure returns (bool) { 18 | return true; 19 | } 20 | 21 | function adminOperation() onlyOwner { 22 | 23 | } 24 | 25 | function withdraw() onlyOwner { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /MultiInheritance.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.4; 4 | 5 | contract A { 6 | 7 | string public name; 8 | string public name2; 9 | 10 | constructor(string memory _name, string memory _name2) { 11 | name = _name; 12 | name = _name2; 13 | } 14 | 15 | function getContractName() public view virtual returns (string memory) { 16 | return name; 17 | } 18 | } 19 | 20 | contract B { 21 | string public helloworld; 22 | 23 | constructor(string memory _helloworld) { 24 | helloworld = _helloworld; 25 | } 26 | 27 | function getHelloworld() public view virtual returns (string memory) { 28 | return helloworld; 29 | } 30 | } 31 | 32 | contract C is A("A1", "A2"), B("HelloWorld") { 33 | 34 | } 35 | 36 | contract D is A, B { 37 | // constructor() A("A1", "A2") B("HelloWorld") { 38 | 39 | // } 40 | constructor(string memory _name, string memory _helloworld) A(_name, _helloworld) B(_helloworld) { 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # learn-smartcontracts-yt -------------------------------------------------------------------------------- /StringUtils.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | library StringUtils { 5 | 6 | function equal(string memory a, string memory b) internal pure returns (bool) { 7 | return keccak256(abi.encode(a)) == keccak256(abi.encode(b)); 8 | } 9 | 10 | function concat(string memory a, string memory b) internal pure returns (string memory) { 11 | return string(abi.encodePacked(a, b)); 12 | } 13 | 14 | function length(string memory str) internal pure returns (uint) { 15 | return bytes(str).length; 16 | } 17 | } 18 | 19 | contract StringUtilsTest { 20 | using StringUtils for string; 21 | 22 | function testEqual(string memory a, string memory b) public pure returns (bool) { 23 | return a.equal(b); 24 | } 25 | 26 | function testConcat(string memory a, string memory b) public pure returns (string memory) { 27 | return a.concat(b); 28 | } 29 | 30 | function testLength(string memory str) public pure returns (uint) { 31 | return str.length(); 32 | } 33 | } -------------------------------------------------------------------------------- /Struct.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Struct { 5 | // what you need to do? task? 6 | // completed? true or false 7 | 8 | struct Todo { 9 | string task; 10 | bool completed; 11 | } 12 | 13 | Todo[] public todoList; 14 | 15 | function create(string memory _task) public { 16 | // Todo memory todo = Todo(_task, false); 17 | 18 | // Todo memory todo = Todo({ 19 | // completed: false, 20 | // task: _task, 21 | // }); 22 | 23 | Todo memory todo; 24 | todo.task = _task; 25 | todo.completed = false; 26 | 27 | todoList.push(todo); 28 | } 29 | 30 | function get(uint _index) public view returns (Todo memory) { 31 | return todoList[_index]; 32 | } 33 | 34 | function getDetails(uint _index) public view returns (string memory task, bool completed) { 35 | Todo storage todo = todoList[_index]; 36 | return (todo.task, todo.completed); 37 | } 38 | 39 | function setTask(uint _index, string memory _task) public { 40 | Todo storage todo = todoList[_index]; 41 | todo.task = _task; 42 | } 43 | 44 | function toggleCompleted(uint _index) public { 45 | Todo storage todo = todoList[_index]; 46 | todo.completed = !todo.completed; 47 | } 48 | } -------------------------------------------------------------------------------- /UniswapExample.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | // Uniswap example 5 | interface UniswapV2Factory { 6 | function getPair(address tokenA, address tokenB) external view returns (address pair); 7 | } 8 | 9 | interface UniswapV2Pair { 10 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 11 | } 12 | 13 | contract UniswapExample { 14 | address private factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f; 15 | address private dai = 0x6B175474E89094C44Da98b954EedeAC495271d0F; 16 | address private weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 17 | 18 | function getTokenReserves() external view returns (uint, uint) { 19 | address pair = UniswapV2Factory(factory).getPair(dai, weth); 20 | (uint reserve0, uint reserve1, ) = UniswapV2Pair(pair).getReserves(); 21 | return (reserve0, reserve1); 22 | } 23 | } -------------------------------------------------------------------------------- /Wallet.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Wallet { 5 | address payable public owner; 6 | 7 | event Deposit(address sender, uint amount, uint balance); 8 | event Withdraw(uint amount, uint balance); 9 | event Transfer(address to, uint amount, uint balance); 10 | 11 | modifier onlyOwner() { 12 | require (msg.sender == owner, "Not Owner"); 13 | _; 14 | } 15 | 16 | constructor() payable { 17 | owner = payable(msg.sender); 18 | } 19 | 20 | function deposit() public payable { 21 | emit Deposit(msg.sender, msg.value, address(this).balance); 22 | } 23 | 24 | function getBalance() public view returns (uint) { 25 | return address(this).balance; 26 | } 27 | 28 | function withdraw(uint amount) public onlyOwner { 29 | payable(msg.sender).transfer(amount); 30 | emit Withdraw(amount, address(this).balance); 31 | } 32 | 33 | function transferTo(address payable _to, uint amount) public onlyOwner { 34 | _to.transfer(amount); 35 | emit Transfer(_to, amount, address(this).balance); 36 | } 37 | } -------------------------------------------------------------------------------- /myLibs/Car.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | contract Car { 5 | string public model; 6 | address public owner; 7 | uint public cost; 8 | 9 | constructor(string memory _model, address _owner) payable { 10 | model = _model; 11 | owner = _owner; 12 | cost = msg.value; 13 | } 14 | } -------------------------------------------------------------------------------- /notes.md: -------------------------------------------------------------------------------- 1 | ganache-cli \ 2 | --fork https://mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID \ 3 | --unlock $WETH_WHALE \ 4 | --unlock $DAI_WHALE \ 5 | --unlock $USDC_WHALE \ 6 | --unlock $USDT_WHALE \ 7 | --unlock $WBTC_WHALE \ 8 | --networkId 999 \ 9 | --port 8545 10 | --------------------------------------------------------------------------------