Last active
August 27, 2022 19:37
-
-
Save jcbombardelli/549a6e743f261283fdaa3857570ced26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract AnimaBank { | |
//Properties | |
address public owner; | |
mapping (address => uint) private balances; | |
//Events | |
event OwnerChanged(address oldOwner, address newOwner); | |
event BalanceIncreased(address to, uint amount); | |
//Modifiers | |
modifier isOwner() { | |
require(msg.sender == owner , "Sender is not owner!"); | |
_; | |
} | |
//Constructor | |
constructor() { | |
// MSG.SENDER é o responsavel pela transação | |
owner = msg.sender; // 0xabc123f....BC | |
} | |
//Public functions | |
function addBalance(address to, uint amount) public isOwner { | |
balances[to] += amount; | |
emit BalanceIncreased(to, amount); | |
} | |
function getBalance() public view returns (uint) { | |
return balances[msg.sender]; | |
} | |
function changeOwner(address newOwnerAnimaBank) public isOwner { | |
emit OwnerChanged(owner, newOwnerAnimaBank); | |
owner = newOwnerAnimaBank; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract AnimaToken { | |
//Properties | |
string public constant name = "AnimaToken"; | |
string public constant symbol = "ANT"; | |
uint8 public constant decimals = 18; | |
uint256 private totalsupply; | |
mapping(address => uint256) private balances; | |
//Events | |
event Transfer(address from, address to, uint256 value); | |
//Constructor | |
constructor(uint256 initialSupply) { | |
totalsupply = initialSupply; | |
balances[msg.sender] = totalsupply; | |
} | |
//Public Functions | |
function totalSupply() public view returns (uint256) { | |
return totalsupply; | |
} | |
function balanceOf(address tokenOwner) public view returns(uint256) { | |
return balances[tokenOwner]; | |
} | |
function transfer(address receiver, uint256 amount) public returns (bool) { | |
require(amount <= balances[msg.sender], "Insufficient Balance to Transfer"); | |
balances[msg.sender] -= amount; // balances[msg.sender] = balances[msg.sender] - amount | |
balances[receiver] += amount; | |
emit Transfer(msg.sender, receiver, amount); | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Storage { | |
// Properties | |
int private numeroArmazenado; | |
//Constructor | |
constructor() { } | |
// Public Functions | |
function get() public view returns (int){ | |
return numeroArmazenado; | |
} | |
function store(int n) public { | |
numeroArmazenado = n; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment