This smart contract aims to distribute cryptocurrency. According to the number of members joining the smart contract and the total number of cryptocurrencies, the smart contract will allocate the same amount of cryptocurrency to the members.
The smart contract is compiled with solidity and the detail of this program is as follows.
pragma solidity >=0.4.22 <0.6.0;- Set compiler version.
address owner;
uint NumOfAccounts;
mapping(address => uint256) accountid;
address payable[] accounts;
uint PriceLimit=100 ether;addressis a type to store address.mappingis a type to transform type and store hash value.payablemeans it is permitted to transfer cryptocurrency.
modifier OnlyOwner(){
require(msg.sender==owner,"Admin only!");
_;
}
modifier OnlyMember(){
if (accounts.length==0){
require(msg.sender==owner,"Member only!");
}
else{
for(uint i=0; i<accounts.length;i++){
require(msg.sender==accounts[i] || msg.sender==owner,"Member only!");
}
}
_;
}- The modifier is usually used as checks before executing functions and check if the user's permissions or balance are sufficient.
_;must be declared at the end of modifier to indicate return.
There are three types of functions in the solidity as follows:


Not Payable and Payable types must pay gas to initiate the transaction except Call type.
function _AddAccount(address payable[]memory _accountAddress) OnlyOwner public {
//account repeat or not
for (uint i=0; i<accounts.length;i++){
for (uint u=0; u<_accountAddress.length;u++){
require(_accountAddress[u]!=accounts[i],"Repaet account!");
}
}
for (uint i=0;i<_accountAddress.length;i++){
uint id = accountid[_accountAddress[i]];
if (id == 0) {
accountid[_accountAddress[0]] = accounts.length;
id = accounts.length++;
}
accounts[id] = _accountAddress[i];
NumOfAccounts++;
}
}- The owner can add multiple members by entering their addresses.
- Input format:
["0xFF","...","0xFF"]
function _RemoveAccount(address _accountAddress) OnlyOwner public {
require(NumOfAccounts>0,"No accounts!");
for (uint i=0; i<accounts.length;i++){
if(accounts[i]==_accountAddress){
delete accounts[i];
delete accountid[_accountAddress];
NumOfAccounts--;
for (uint u = i; u<accounts.length-1; u++){
accounts[u] = accounts[u+1];
}
accounts.length--;
}
}
}- The owner can delete a member by entering his address.
- Input format:
0xFF
function _RemoveAllAccount() OnlyOwner public {
require(NumOfAccounts>0,"No accounts!");
for (uint i=0; i<accounts.length;i++){
delete accountid[accounts[i]];
NumOfAccounts--;
}
delete accounts;
}- The owner can delete all the members.
function _ReturnAllMoney()public payable OnlyOwner{
require(address(this).balance > 0,"No money!");
msg.sender.transfer(address(this).balance);
}- The owner can withdraw all the cryptocurrency.
function _SplitAllMoney()public payable OnlyOwner{
require(address(this).balance > 0,"No money!");
uint ShareMoney=address(this).balance/(accounts.length);
for (uint i=0; i<accounts.length;i++){
accounts[i].transfer(ShareMoney);
}
}- The owner can split the cryptocurrency to each member equally.
function AddYourAccountOnly () public{
for (uint i=0; i<accounts.length;i++){
require(msg.sender!=accounts[i],"Repaet account!");
}
uint id = accountid[msg.sender];
if (id == 0) {
accountid[msg.sender] = accounts.length;
id = accounts.length++;
}
accounts[id] = msg.sender;
NumOfAccounts++;
}- Everyone can join the membership yourself.
function DeleteYourAccountOnly() public{
require(accounts.length>0,"No accounts!");
for (uint i=0; i<accounts.length;i++){
require(accounts[i]==msg.sender,"Not in this contract!");
if(accounts[i]==msg.sender){
delete accounts[i];
delete accountid[msg.sender];
NumOfAccounts--;
for (uint u = i; u<accounts.length-1; u++){
accounts[u] = accounts[u+1];
}
accounts.length--;
}
}
}- Everyone can delete the membership yourself.
function Deposit() public payable{
require(msg.value>0 && msg.value < PriceLimit,"Deposit at most 100 ether!");
}- Everyone can deposit the cryptocurrency into smart contract.
function GetAllAccountID()public OnlyMember view returns(address payable[] memory){
return accounts;
}- The members can view all the membership's ID.
function GetBalance() public OnlyMember view returns(uint) {
return address(this).balance;
}- The members can view all the balance from the smart contract.
function GetNumOfAccounts() public OnlyMember view returns(uint) {
return NumOfAccounts;
}- The members can view all the number of members.






















