├── .gitattributes ├── README.md ├── Contract.sol ├── RoomReservation.sol ├── MultiContract.sol └── Mapping.sol /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Solidity-Smart-Contracts 2 | This Reository contains Solidity Smart Contracts Practice Projects and also full Contracts 3 |

1) Contract.sol

4 |

This is Practice project of Solidity smart contract contains Function,structure,pure function,differernt datatypes

5 |

2) Mapping.sol

6 |

This Practice Project of Solidity smart contract contains Uses of Mapping and Mapping with Structure

7 |

3) RoomReservation.sol

8 |

This Smart contract Project demonstrate the basic idea and strategy of Room Reservation in Hotel in it i have used functions like Payment Transfer, Events ,Modifiers and some other functions

9 |

4) MultiContract.sol

10 |

This Practice Project of Solidity smart contract contains Uses of inheritance , interaction with other smart contracts , Factories

11 | -------------------------------------------------------------------------------- /Contract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: SEE LICENSE IN LICENSE 2 | pragma solidity ^0.8.15; 3 | 4 | contract Mycontract { 5 | uint public Uint_var; 6 | string public Mystring; 7 | address public Address; 8 | 9 | 10 | struct MyStruct { 11 | uint Suint; 12 | string Sstring; 13 | } 14 | 15 | MyStruct public Obj; 16 | 17 | function setstruct() public{ 18 | 19 | Obj.Suint=1; 20 | Obj.Sstring="MRX"; 21 | } 22 | 23 | 24 | 25 | function String(string memory value) public{ 26 | Mystring=value; 27 | } 28 | 29 | function Number(uint value) public{ 30 | Uint_var=value; 31 | 32 | } 33 | 34 | function SetAddress(address value) public{ 35 | Address=value; 36 | } 37 | 38 | function GetAddress() public view returns (uint) { 39 | return Address.balance; 40 | } 41 | 42 | function getvalue() public pure returns (uint) //pure functions means it doesnt modify or read from state variable 43 | { 44 | uint value; 45 | return value; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /RoomReservation.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: SEE LICENSE IN LICENSE 2 | pragma solidity ^0.7.4; 3 | contract RoomReservation { 4 | 5 | //events 6 | //modifiers 7 | //functions 8 | //payment transfer 9 | 10 | 11 | enum Status {Occupied,Vacant} 12 | Status public CurrentStatus; 13 | event Occupy(address Occupant,uint value); 14 | address payable Owner; 15 | 16 | 17 | constructor() { 18 | Owner=msg.sender; 19 | CurrentStatus=Status.Vacant; 20 | } 21 | 22 | function CheckOwner() public view returns (bool) { 23 | 24 | if (Owner==msg.sender) 25 | return true; 26 | else 27 | return false; 28 | } 29 | modifier statuses { 30 | require(CurrentStatus == Status.Vacant,"ROOM OOCUPIED"); 31 | _; 32 | } 33 | modifier PriceCheck(uint _value) { 34 | require(msg.value >=_value,"No enough payment"); 35 | _; 36 | } 37 | 38 | 39 | function BookRoom ()public payable statuses PriceCheck(2 ether){ 40 | CurrentStatus=Status.Occupied; 41 | (bool sent, bytes memory _data)= Owner.call{value: msg.value}("Hi"); 42 | require(sent); 43 | emit Occupy(msg.sender,msg.value); 44 | } 45 | 46 | 47 | } -------------------------------------------------------------------------------- /MultiContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: SEE LICENSE IN LICENSE 2 | pragma solidity ^0.7.4; 3 | 4 | contract Owner { 5 | address owner; 6 | 7 | constructor() { 8 | owner=msg.sender; 9 | } 10 | 11 | modifier CheckOwner { 12 | require(owner==msg.sender,"You are Not Owner"); 13 | _; 14 | } 15 | } 16 | contract SecertVault { 17 | 18 | string secert; 19 | address OwnerAddress; 20 | string date; 21 | 22 | constructor(string memory A,string memory C) 23 | { 24 | secert=A; 25 | OwnerAddress=msg.sender; 26 | date=C; 27 | 28 | } 29 | 30 | function getdata() public view returns (string memory,address,string memory) { 31 | return(secert,OwnerAddress,date); 32 | } 33 | } 34 | 35 | 36 | contract MultiContract is Owner { 37 | address obj; 38 | 39 | constructor(string memory Secret, string memory Date) 40 | { 41 | super; 42 | SecertVault _vault = new SecertVault(Secret,Date); 43 | obj=address(_vault); 44 | } 45 | 46 | function Get_Secrets() public view CheckOwner returns (string memory,address,string memory) { 47 | return SecertVault(obj).getdata(); 48 | } 49 | 50 | 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Mapping.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: SEE LICENSE IN LICENSE 2 | pragma solidity ^0.7.4; 3 | contract Maps { 4 | 5 | //simple mapping setter and getter 6 | mapping (uint => string) public oneBooks; //declare and getter function 7 | 8 | function onesetbooks(uint id,string memory Booknam) public{ 9 | 10 | oneBooks[id] = Booknam; 11 | 12 | } 13 | 14 | mapping (address => mapping (uint => string)) public oneBook_Collections; //dec and getter function 15 | 16 | function oneset_Col(uint id,string memory Booknam) public { 17 | oneBook_Collections[msg.sender][id] = Booknam; 18 | } 19 | 20 | struct Details { 21 | string name; 22 | string author; 23 | string release; 24 | } 25 | 26 | mapping (uint => Details) public Books; //declare and getter function 27 | 28 | function setbooks(uint id,string memory name,string memory author,string memory release) public{ 29 | 30 | Books[id] = Details(name,author,release); 31 | 32 | } 33 | 34 | mapping (address => mapping (uint => Details)) public Book_Collections; //dec and getter function 35 | 36 | function set_Col(uint id,string memory name,string memory author,string memory release) public { 37 | Book_Collections[msg.sender][id] = Details(name,author,release); 38 | } 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | } --------------------------------------------------------------------------------