Creating a Smart Contract that Returns Address and Balance of Owner using Solidity Last Updated : 11 May, 2022 Comments Improve Suggest changes Like Article Like Report 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. Solidity // Solidity program to // retrieve address and // balance of owner pragma solidity ^0.6.8; // Creating a contract contract MyContract { // Private state variable address private owner; // Defining a constructor constructor() public{ owner=msg.sender; } // Function to get // address of owner function getOwner( ) public view returns (address) { return owner; } // Function to return // current balance of owner function getBalance( ) public view returns(uint256){ return owner.balance; } } 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. Comment More infoAdvertise with us Next Article Creating a Smart Contract that Returns Address and Balance of Owner using Solidity M muskan02 Follow Improve Article Tags : Solidity Blockchain Similar Reads Building a Simple Fixed Deposit Application Using Solidity Smart Contracts Blockchain technology has revolutionized the way we handle financial transactions, and the world of decentralized finance (DeFi) is growing at an unprecedented rate. One of the most intriguing aspects of this financial evolution is the use of smart contracts, which are self-executing agreements with 13 min read Steps to Execute Solidity Smart Contract using Remix IDE Remix IDE is generally used to compile and run Solidity smart contracts. Below are the steps for the compilation, execution, and debugging of the smart contract. Step 1: Open Remix IDE on any of your browsers, select on New File and click on Solidity to choose the environment. Step 2: Write the Smar 1 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 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 Like