Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Solidity Introduction
  • Solidity - Environment Setup
  • Solidity - Basic Syntax
  • Solidity - Types
  • Solidity - Operators
  • Solidity - Mappings
  • Solidity - Functions
  • Solidity - Fallback Function
  • Mathematical Functions
  • Solidity - Inheritance
  • Solidity - Constructors
  • Solidity - Interfaces
  • Solidity - Events
  • Solidity - Error Handling
Open In App
Next Article:
What is Wallet Smart Contract?
Next article icon

What is Wallet Smart Contract?

Last Updated : 27 Feb, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Wallets are just like your bank account, through which we can receive money, send money, and can check the balance.

Important terms:

  1. uint- unsigned integer.
  2. address- It is a unique set of the string provided for the transaction.
  3. msg.sender- Address of the current user.
  4. msg.value- Cost put by the current user.
  5. public- Visibility of the function.
  6. view- This keyword is used when the function is read-only.
  7. 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.

Depositing Money into the Contract Account owned by the owner

Solidity
// SPDX-License-Identifier: GPL-3.0  pragma solidity >=0.4.22 <0.9.0;   /// @title A contract for demonstrate Wallet Smart Contract /// @author Jitendra Kumar /// @notice For now, this contract just show how to depositing money into the contract account owned by the owner contract 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() payable{                              // msg.sender is the address of the         // person who has currently deployed contract         Owner = payable(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.

Depositing money into the Owner's account instead of the Contract Account.

Solidity
// SPDX-License-Identifier: GPL-3.0  pragma solidity >=0.4.22 <0.9.0;   /// @title A contract for demonstrate Wallet Smart Contract /// @author Jitendra Kumar /// @notice For now, this contract just show how to depositing money into the Owner's account instead of the contract account. contract 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() payable{          // msg.sender is the address of the person     // who has currently deployed contract     Owner= payable(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 onlyOwner 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];         } } 

Next Article
What is Wallet Smart Contract?

M

mukesh01
Improve
Article Tags :
  • Solidity

Similar Reads

    What is Smart Contract in Solidity?
    Solidity's code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. A contract is a fundamental block of building an application on Ethereum.  Now let's look at the
    4 min read
    What is MultiSignature Wallets?
    Digital wallets are financial accounts that store funds and make transactions. You can also track transaction histories. Instead of using rupees, dollars we can also use cryptocurrencies such as Bitcoin, Ether, and many more. Generally, a wallet needs one signature to sign a transaction. We can also
    14 min read
    Decentralized Bank Smart Contract in Solidity
    Solidity is an Object-oriented Programming Language for implementing Smart Contracts. It's a High-Level Statically Typed Language like C. The solidity file has an extension .sol. The article focuses on discussing the decentralized bank smart contract in Solidity. In the below example, the aim is to
    3 min read
    Steps to Create, Test and Deploy Ethereum Smart Contract
    Smart contracts are self-execution programs stored on a blockchain that are automatically executed when predefined conditions are met. They allow the participants on the blockchain to transact with each other without a trusted central authority. After creating a smart contract, the next step is to d
    7 min read
    Setting Up Smart Contract Development Environment
    A development environment is an environment in which all the resources and tools are available which are used to develop a program or software product. Here, an attempt to create a development environment that is a collection of the processes and tools that are used to develop smart contracts.There
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences