What is Wallet Smart Contract? - GeeksforGeeks

09 Jul, 2020
Wallets are just like your bank account, through which we can receive money, send money, and can check the balance.
uint- unsigned integer.address- It is a unique set of the string provided for the transaction.msg.sender- Address of the current user.msg.value- Cost put by the current user.public- Visibility of the function.view- This keyword is used when the function is read-only.modifier- modifier is just like a function, which is used at, the initial point of function so that it can check the required condition and prevent wastage of ether before function execution.
uint- unsigned integer.
address- It is a unique set of the string provided for the transaction.
msg.sender- Address of the current user.
msg.value- Cost put by the current user.
public- Visibility of the function.
view- This keyword is used when the function is read-only.
modifier- modifier is just like a function, which is used at, the initial point of function so that it can check the required condition and prevent wastage of ether before function execution.
Solidity
// pragma is the directive through// which we write the smart contract  pragma solidity 0.6.0;                              // Creating a contractcontract wallet{     // Specify the owner's address    // which is publicly visible    address payable public Owner;     // mapping is created for mapping    // address=>uint for transaction    mapping(address=>uint) Amount;          // Defining a constructor    // constructor is payable, which means    // it cost ether during the deployment    constructor() public  payable{                             // msg.sender is the address of the       // person who has currently deployed contract        Owner = msg.sender                              // msg.value is the value of the ether we are        // giving during the deploying of contract        Amount[Owner] = msg.value;         }     // modifier(onlyOwner) it will check    // the required condition, here condition    // is the only owner can call this function    modifier onlyOwner(){         // require is used whether the        // owner is the person who has        // deployed the contract or not        require(Owner == msg.sender);        _;    }    // Defining a function which is   // used to send money   function sendMoney(      address payable receiver,  uint amount)                       public payable onlyOwner {          // receiver account balance should be>0         require( receiver.balance>0);                   // amount should not be negative,        // otherwise it will throw error        require(amount>0);                                 Amount[Owner] -= amount;         Amount[receiver] += amount;    }     // Defining function for Receiving money    // to our smart contract account    // not to an owners account    function ReceiveMoney() public payable{    }      // This function will return the current    // balance of the contract account owned    // by the owner    function CheckBalance_contractAccount()      public view onlyOwner returns(uint){         return address(this).balance;    }     // Defining a function that will return   // the current balance of the owner's account   function CheckBalance()     public view onlyOwner returns(uint){          return Amount[Owner];   }    }
In the above code, money is deposited in the contract account, not in the owner’s account. Let us discuss a code in which we will see how to send ether directly into the owner’s account.
Solidity
// pragma is the directive through which// we write the smart contractpragma solidity 0.6.0; // Creating a contractcontract wallet{      // Specify the owner's address     // which is publicly visible     address payable public Owner;       // Mapping is done from     // address=>uint for transaction      mapping(address => uint) Amount;            // Constructor 'payable' is created,     // which means it cost ether during the     // deployment      constructor() public payable{            // msg.sender is the address of the person     // who has currently deployed contract         Owner = msg.sender           // msg.value is the value of the ether we     // are giving during the deploying of contract      Amount[Owner] = msg.value;     }                 // Modifier is created      modifier onlyOwner(){                    // require is used whether the owner is the        // person who has deployed the contract or not         require(Owner == msg.sender);         _;        }        // Defining a function to send money,     // we have used modifier(onlyOwner)     // it will check the required condition,     // here condition is the only owner can     // call this function      function sendMoney(       address payable receiver, uint amount)       public payable onlyOwner {                    // receiver account balance should be > 0           require( receiver.balance>0);                     // amount should not be negative ,         // otherwise it throw error           require(amount >0);                       Amount[Owner] -= amount;           Amount[receiver] += amount;      }                // Defining a function to receive money             function ReceiveMoney() public payable{                       // Receiving money in owners         // account directly           Amount[Owner] += msg.value;      }                // Defining a function to return         // the balance of the contract         // account owned by the owner         function CheckBalance_contractAccount()           public view onlyOwwner returns(uint){                       // return the balance of contract         // account owned by owner           return address(this).balance;           }           // Defining a function to check the         // current balance of the owner account         function CheckBalance()           public view onlyOwner returns(uint){                               // return the current balance                 // of the owner's account                 return Amount[Owner];          }}
Solidity
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Solidity - Constructors
Solidity - Operators
Solidity - Inheritance
Mathematical Operations in Solidity
Solidity - Fall Back Function
Solidity - While, Do-While, and For Loop
Introduction to Solidity
Dynamic Arrays and its Operations in Solidity
Solidity - Types
Solidity - View and Pure Functions