-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.sol
More file actions
42 lines (32 loc) · 1.3 KB
/
example.sol
File metadata and controls
42 lines (32 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0 <0.9.0;
import "hardhat/console.sol";
contract Token{
string public name = "Aarav Token";
string public symbol = "HHT";
uint public totalSupply = 10000;
address public owner;
mapping(address => uint256) balances;
constructor(){
balances[msg.sender]=totalSupply;
owner=msg.sender;
}
receive() external payable{
console.log("**** I AM IN RECEIVE");
}
fallback() external payable{
console.log("**** I AM IN FALLBACK");
}
function transfer(address to, uint amount) external{
require(balances[msg.sender]>=amount, "Insufficient tokens");
console.log("**** %s IS TRANSFERING %s TOKENS TO %s", msg.sender, amount, to);
balances[msg.sender]-=amount; // balances[msg.sender] = balances[msg.sender] - amount;
console.log("**** Sender balance is %s tokens", balances[msg.sender]);
balances[to]+=amount; // balances[msg.sender] = balances[msg.sender] - amount;
console.log("**** Receiver balance is %s tokens", balances[to]);
}
function getBalance(address account) external view returns(uint){
console.log("**** Current balance of %s is %s tokens", account, balances[account]);
return balances[account];
}
}