Problem: Create a smart contract named MyContract having a state variable as owner. Create a constructor to fetch the address of the owner from msg and hold it into the state variable owner. Also, create a function getBalance() to show the current balance of the owner.
Solution: Every smart contract is owned by an address called as owner. A smart contract can know its owner’s address using sender property and its available balance using a special built-in object called msg.
Step 1: Open Remix-IDE.
Step 2: Select File Explorer from the left side icons and select Solidity in the environment. Click on New option below the Solidity environment. Enter the file name as MyContract.sol and Click on the OK button.
Step 3: Enter the following Solidity Code.
Step 4: Compile the file MyContract.sol from the Solidity Compiler tab.
Step 5: Deploy the smart contract from the Deploy and Run Transaction tab and you will get the balance and address of the owner.
Step 6: The output below shows the address and the balance of the owner.
- Steps to Execute Solidity Smart Contract using Remix IDE
- What is Smart Contract in Solidity?
- How to use MetaMask to Deploy a Smart contract in Solidity (Blockchain)?
- What is Escrow Smart Contract?
- What is Wallet Smart Contract?
- Smart Contract to Store Employee Details
- Solidity - Abstract Contract
- Random Number Generator in Solidity using keccak256
- Blockchain | Smart Contracts
- Solidity - View and Pure Functions
- Solidity - While, Do-While, and For Loop
- Solidity - Break and Continue Statements
- Solidity - Enums and Structs
- Solidity - Types
- Solidity - Functions
- What are Events in Solidity?
- Solidity - Inheritance
- Solidity - Polymorphism
- Solidity - Encapsulation
- How to Install Solidity in Windows?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.