Loading...
In this smart contract, we'll discuss the smart contracts.
In my previous, I created a contract to send the amount and check the balance. My problem is I check any address balance not only for the msg.sender.
Then what do we do?
we create a function and inside this function passed one parameter and the data type is the address type.
function checkBalance(address _add) override public view returns(uint){
return balances[_add];
}
In mapping, they check the address value in which uint is stored.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.5 <0.9.0;
interface ERC {
function transfer(address receiver, uint amount) external returns(bool);
function checkBalance(address add) external returns(uint);
event Transfer(address from, address to, uint value) ;
}
contract MyContract is ERC{
uint totalSupply = 1000;
address owner;
mapping ( address => uint ) balances;
constructor(){
owner = msg.sender;
balances[owner] = totalSupply;
}
function transfer(address _to, uint _value) override public returns(bool){
require( balances[owner] >= _value, "Not enough amount" );
balances[owner] -= _value;
balances[_to] += _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function checkBalance(address _add) override public view returns(uint){
return balances[_add];
}
}