This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: GPL-3.0 | |
pragma solidity ^0.8.0; | |
/* | |
Declare a state variable for setting the maximum number of whitelisted addresses to be allowed. | |
Use mapping for maintaining a list of addresses and if they are whitelisted or not. | |
Initialize a maximum number of whitelisting addresses allowed using a constructor. | |
Write a function to add the address to the whitelist. | |
Write a function to check if the address is whitelisted or not. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >= 0.7.0 < 0.8.18; | |
/*Set the owner to the deployer of the contract using the constructor. | |
Use mapping to keep track of each Task. | |
Write the modifier onlyOwner() so that only the owner can call certain functions. | |
Adding a new task to the list. | |
Fetching (Reading) the task from the list. | |
Mark the task as completed.*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >= 0.7.0 < 0.8.18; | |
contract Lottery{ | |
address public manager; | |
address payable[] public players; | |
constructor(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
//solidity cryptographics builtin hash functions | |
contract HashFun{ | |
//builtin functions | |
//keccak256 | |
//hash256 | |
//ripemd160 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract DataLocation{ | |
uint[] public arr = [1,4,5,7,9,10,15]; | |
//by default state variable store in storage | |
function Storage() public { | |
uint[] storage arrs = arr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract Immutable{ | |
//immutable state variable can be set inline - constructor | |
address public immutable owner; | |
//constant defined only inline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract SentEther{ | |
//address payable public getter = payable(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2); | |
//add the ether in the smart contract using transact | |
receive() external payable{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract fallback_receive{ | |
event logs(string _msg,address _sender,uint _val,bytes _data); | |
//fallback is used to received the data but if received isn't present in contract | |
// than fallback handle the received functionality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract Payable{ | |
// address make it payable | |
address payable public owner = payable(msg.sender); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
contract modifiers{ | |
address public owner = msg.sender; | |
uint public _xx = 10; | |
//modifier is used to reuse the same code from the starting or ending of the function |