├── LICENSE ├── README.md ├── charitySmartContract.sol ├── dataType_MSG.sol ├── dataType_sturct.sol ├── dataTypes_maps.sol └── lakshmi_lottery_system.sol /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # solidity-code-blockchain -------------------------------------------------------------------------------- /charitySmartContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.13 <0.7.3; 2 | 3 | contract charitySmartContract{ 4 | address public owner; 5 | bool public isPause; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | function recieveEthers() public payable { 12 | } 13 | function withdrawAllEthers() public{ 14 | require(msg.sender == owner, "You Cannot Withdraw All ethers Coz you are not the owner"); 15 | require(!isPause, "Contract is Paused, we cnt withdraw the money"); 16 | address payable to = msg.sender; 17 | to.transfer(address(this).balance); 18 | } 19 | 20 | function setPause( bool _ispause) public{ 21 | require(msg.sender == owner, "You Dont have access to this function"); 22 | isPause = _ispause; 23 | } 24 | 25 | function setNewOwner( address _newOwner) public{ 26 | require(msg.sender == owner, "You Dont have access to this function"); 27 | require(!isPause, "Contract is Paused, we cnt withdraw the money"); 28 | owner = _newOwner; 29 | } 30 | 31 | function terminateThisSmartContract() public{ 32 | require(msg.sender == owner, "You Dont have access to this function"); 33 | require(!isPause, "Contract is Paused, we cnt withdraw the money"); 34 | address payable to = msg.sender; 35 | selfdestruct(to); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /dataType_MSG.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.13 < 0.7.3; 2 | 3 | contract dataTypes{ 4 | 5 | address public myAddr; 6 | uint256 public totalBal; 7 | 8 | constructor() public{ 9 | myAddr = msg.sender; // This is storing the value of the deploying account 10 | } 11 | function reciveEthers() public payable { 12 | totalBal += msg.value; 13 | } 14 | function withdrawEthers() public{ 15 | address payable to = msg.sender; 16 | to.transfer(address(this).balance); 17 | } 18 | function withdrawEthersToThisEOA(address payable _EOAAddr ) public{ 19 | _EOAAddr.transfer(address(this).balance); 20 | } 21 | 22 | function currentEtherInContrat() public view returns(uint256){ 23 | return address(this).balance; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /dataType_sturct.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.13 <0.7.3; 2 | 3 | contract charitySmartContract{ 4 | address public owner; 5 | 6 | struct paymentDetails { 7 | uint256 amount; 8 | string name; 9 | } 10 | 11 | mapping(address => paymentDetails) public addressToEtherMap; 12 | 13 | constructor() public { 14 | owner = msg.sender; 15 | } 16 | 17 | function recieveEthers(string memory _name) public payable { 18 | paymentDetails memory pay = paymentDetails(msg.value,_name); 19 | addressToEtherMap[msg.sender] = pay; 20 | } 21 | 22 | function withdrawAllEthersOfSpecificAccount(address payable _to) public{ 23 | _to.transfer(addressToEtherMap[_to].amount); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dataTypes_maps.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.13 <0.7.3; 2 | 3 | contract charitySmartContract{ 4 | address public owner; 5 | 6 | mapping(address => uint) public addressToEtherMap; 7 | 8 | constructor() public { 9 | owner = msg.sender; 10 | } 11 | 12 | function recieveEthers() public payable { 13 | addressToEtherMap[msg.sender] = msg.value; 14 | } 15 | 16 | function withdrawAllEthersOfSpecificAccount(address payable _to) public{ 17 | _to.transfer(addressToEtherMap[_to]); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /lakshmi_lottery_system.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.13 < 0.7.3; 2 | 3 | contract LakshmiLotterySystem{ 4 | 5 | address owner; 6 | 7 | mapping(address => uint) public addressOfLotteryParticipants; 8 | address[] addressOfPartipant; 9 | 10 | constructor() public { 11 | owner = msg.sender; 12 | } 13 | 14 | function reciveEtherForParticpation() payable public{ 15 | require(msg.value>= 1 ether , " You require minumum 1 ether to participate in this lottery"); 16 | require(contains(msg.sender)==0, " You are already a part of the lottery"); 17 | addressOfLotteryParticipants[msg.sender] = msg.value; 18 | addressOfPartipant.push(msg.sender); 19 | } 20 | 21 | function randomNumberFunction() private view returns(uint){ 22 | uint randomNumber = uint(keccak256(abi.encodePacked(block.difficulty, 23 | block.timestamp, msg.sender,"Prabhpreet", addressOfPartipant))) % addressOfPartipant.length; 24 | return(randomNumber); 25 | } 26 | 27 | function transferEhterToWinner() public onlyOwner{ 28 | uint randomWinner = randomNumberFunction(); 29 | address payable winner = payable(addressOfPartipant[randomWinner]); 30 | winner.transfer(address(this).balance); 31 | } 32 | 33 | modifier onlyOwner(){ 34 | require(msg.sender == owner, "Owner only has access to this"); 35 | _; 36 | } 37 | 38 | function contains( address _addr) private view returns(uint) { 39 | return addressOfLotteryParticipants[_addr]; 40 | } 41 | } 42 | --------------------------------------------------------------------------------