Created
January 11, 2023 12:48
-
-
Save ratul16/fcc992f892ce4b9f5ae8a602b33d7fc5 to your computer and use it in GitHub Desktop.
smart contract sample code
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; | |
contract SolidityTest { | |
// constructor() public{ | |
// } | |
function getResult() public view returns(uint){ | |
uint a = 6; | |
uint b = 10; | |
return a + b; | |
} | |
} | |
// =============================================== | |
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.8.0; | |
contract DataStorge { | |
uint storeData; | |
function set(uint x) public { | |
storeData = x; | |
// storeData = block.difficulty; //encrypts the data of the variable | |
// storeData = block.timestamp; | |
// storeData = block.number; | |
} | |
function get() public view returns(uint result) { | |
return storeData; | |
} | |
} | |
// =================================================== | |
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.8.0; | |
contract donutMachine { | |
address public owner; | |
mapping (address => uint) public numberOfDonut; | |
constructor() { | |
owner = msg.sender; | |
numberOfDonut[address(this)] = 200; | |
} | |
function getRemaingDonuts() public view returns(uint) { | |
return numberOfDonut[address(this)]; | |
} | |
function purchase(uint amount) public payable { | |
require(msg.value >= amount * 2 ether, "You must pay 2 ETH per donut"); | |
require(numberOfDonut[address(this)] >= amount); | |
numberOfDonut[address(this)] -= amount; | |
numberOfDonut[msg.sender] += amount; | |
} | |
function restock(uint amount) public { | |
require(msg.sender == owner, "Only the owner can restock"); | |
numberOfDonut[address(this)] += amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment