Created
March 19, 2021 22:30
-
-
Save victor35/55d178d6db543c7301ba69e5d930dff3 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=
This file contains 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
REMIX EXAMPLE PROJECT | |
Remix example project is present when Remix loads very first time or there are no files existing in the File Explorer. | |
It contains 3 directories: | |
1. 'contracts': Holds three contracts with different complexity level, denoted with number prefix in file name. | |
2. 'scripts': Holds two scripts to deploy a contract. It is explained below. | |
3. 'tests': Contains one test file for 'Ballot' contract with unit tests in Solidity. | |
SCRIPTS | |
The 'scripts' folder contains example async/await scripts for deploying the 'Storage' contract. | |
For the deployment of any other contract, 'contractName' and 'constructorArgs' should be updated (along with other code if required). | |
Scripts have full access to the web3.js and ethers.js libraries. | |
To run a script, right click on file name in the file explorer and click 'Run'. Remember, Solidity file must already be compiled. | |
Output from script will appear in remix terminal. |
This file contains 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
pragma solidity ^0.6.6; | |
contract BankContract { | |
struct client_account{ | |
int client_id; | |
address client_address; | |
uint client_balance_in_ether; | |
} | |
client_account[] clients; | |
int clientCounter; | |
address payable manager; | |
mapping(address => uint) public interestDate; | |
modifier onlyManager() { | |
require(msg.sender == manager, "Only manager can call this!"); | |
_; | |
} | |
modifier onlyClients() { | |
bool isclient = false; | |
for(uint i=0;i<clients.length;i++){ | |
if(clients[i].client_address == msg.sender){ | |
isclient = true; | |
break; | |
} | |
} | |
require(isclient, "Only clients can call this!"); | |
_; | |
} | |
constructor() public{ | |
clientCounter = 0; | |
} | |
receive() external payable { } | |
function setManager(address managerAddress) public returns(string memory){ | |
manager = payable(managerAddress); | |
return ""; | |
} | |
function joinAsClient() public payable returns(string memory){ | |
interestDate[msg.sender] = now; | |
clients.push(client_account(clientCounter++, msg.sender, address(msg.sender).balance)); | |
return ""; | |
} | |
function deposit() public payable onlyClients{ | |
payable(address(this)).transfer(msg.value); | |
} | |
function withdraw(uint amount) public payable onlyClients{ | |
msg.sender.transfer(amount * 1 ether); | |
} | |
function sendInterest() public payable onlyManager{ | |
for(uint i=0;i<clients.length;i++){ | |
address initialAddress = clients[i].client_address; | |
uint lastInterestDate = interestDate[initialAddress]; | |
if(now < lastInterestDate + 10 seconds){ | |
revert("It's just been less than 10 seconds!"); | |
} | |
payable(initialAddress).transfer(1 ether); | |
interestDate[initialAddress] = now; | |
} | |
} | |
function getContractBalance() public view returns(uint){ | |
return address(this).balance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment