├── Solidity ├── Structure.sol ├── bytes.sol ├── conditional.sol ├── enum.sol ├── identity.sol ├── loops.sol ├── mapping.sol ├── mapping2.sol ├── overflow.sol └── payment.sol └── Web3.js ├── .gitignore ├── Documents.md ├── demo.sol ├── index.html ├── package-lock.json ├── package.json └── web3-new.js /Solidity/Structure.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | struct Student { 6 | uint roll; 7 | string name; 8 | } 9 | 10 | contract Demo { 11 | 12 | Student public s1; 13 | 14 | constructor (uint _roll, string memory _name){ 15 | s1.roll = _roll; 16 | s1.name = _name; 17 | } 18 | 19 | function change (uint _roll, string memory _name) public { 20 | 21 | Student memory newStudent = Student({ 22 | roll: _roll, 23 | name: _name 24 | }); 25 | s1 = newStudent; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Solidity/bytes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract by{ 6 | 7 | bytes public b1; 8 | 9 | function pushelement() public { 10 | b1.push('d'); 11 | } 12 | 13 | function getelement (uint i) public view returns (bytes1) { 14 | return b1[i]; 15 | } 16 | 17 | function getLength () public view returns(uint){ 18 | return b1.length; 19 | } 20 | } -------------------------------------------------------------------------------- /Solidity/conditional.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract condition { 6 | 7 | function conditions (int a) public pure returns(string memory){ 8 | 9 | string memory value; 10 | 11 | if(a == 0){ 12 | value = "It's a zero"; 13 | } 14 | else if(a > 0){ 15 | value = "Bhai positive hai"; 16 | } 17 | else{ 18 | value = "Bhai ye to negative nikla"; 19 | } 20 | return value; 21 | } 22 | } -------------------------------------------------------------------------------- /Solidity/enum.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract Enum { 6 | 7 | enum user {allowed, not_allowed, wait} 8 | user u1 = user.allowed; 9 | uint public lottery = 1000; 10 | 11 | function Owner() public { 12 | 13 | if (u1 == user.allowed){ 14 | lottery = 0; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Solidity/identity.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL 3.0 2 | 3 | pragma solidity >= 0.5.0 < 0.9.0; 4 | 5 | contract Identity { 6 | 7 | string name; 8 | uint age; 9 | 10 | constructor() { 11 | 12 | name = "Vishal"; 13 | age = 21; 14 | } 15 | 16 | function getName () view public returns (string memory) { 17 | return name; 18 | } 19 | 20 | function getAge () view public returns (uint) { 21 | return age; 22 | } 23 | } -------------------------------------------------------------------------------- /Solidity/loops.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract loops { 6 | 7 | uint[3] public arr; 8 | uint public count; 9 | 10 | function loop() public { 11 | while (count < arr.length){ 12 | arr[count] = count; 13 | count++; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Solidity/mapping.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract Map { 6 | 7 | mapping (uint => string) public roll_no; 8 | 9 | function setter(uint keys, string memory value) public { 10 | 11 | roll_no[keys] = value; 12 | } 13 | } -------------------------------------------------------------------------------- /Solidity/mapping2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract Map2 { 6 | 7 | struct Student { 8 | string name; 9 | uint class; 10 | } 11 | 12 | mapping (uint => Student) public data; 13 | 14 | function setter (uint _roll, string memory _name, uint _class) public { 15 | 16 | data[_roll] = Student(_name,_class); 17 | } 18 | } -------------------------------------------------------------------------------- /Solidity/overflow.sol: -------------------------------------------------------------------------------- 1 | //Overflow condition in smart contract 2 | 3 | // SPDX-License-Identifier: GPL-3.0 4 | 5 | pragma solidity >= 0.5.0; 6 | 7 | contract overflow{ 8 | 9 | uint8 public money = 255; 10 | 11 | function setdata() public{ 12 | money = money + 1; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Solidity/payment.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0 2 | 3 | pragma solidity >= 0.7.0; 4 | 5 | contract pay { 6 | 7 | address payable user = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2); 8 | 9 | function payether() public payable { 10 | 11 | } 12 | 13 | function getbalance() public view returns(uint) { 14 | return address(this).balance; 15 | } 16 | 17 | function sendether() public { 18 | user.transfer(1 ether); 19 | } 20 | } -------------------------------------------------------------------------------- /Web3.js/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /Web3.js/Documents.md: -------------------------------------------------------------------------------- 1 | # Commands related to Web3.js 2 | 3 | 1. To install web3 - npm install --save web3 4 | 2. To import web3 - let Web3 =require("web3"); 5 | 3. To connect with Ganache - let web3 = new Web3(new Web3.providers.HttpProvider("[HTTP://127.0.0.1:7545]")); [Remember that the ganache must be running] 6 | 7 | 4. To get the balance of an account - web3.eth.getBalance("paste the address of the account inside it").then(console.log); 8 | 9 | 5. To convert wei into ether - web3.eth.getBalance("paste the address of the account inside it").then(function(result) {console.log(web3.utils.fromWei(result,"ether"));}) 10 | 11 | 6. To transfer ether from one account to another - web3.eth.sendTransaction({from:"paste the address of the account inside it",to:"paste the address of the account inside it",value:web3.utils.toWei("1","ether")}); 12 | -------------------------------------------------------------------------------- /Web3.js/demo.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >= 0.8.21; 4 | 5 | contract demo { 6 | 7 | uint public x = 10; 8 | 9 | function set (uint _x) public { 10 | x = _x; 11 | } 12 | } -------------------------------------------------------------------------------- /Web3.js/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |