-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
367b156
commit f745bd0
Showing
8 changed files
with
1,240 additions
and
1,427 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
pragma solidity 0.8.23; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
error SimpleCoin__NotEnoughBalance(); | ||
|
||
contract SimpleCoin { | ||
mapping (address => uint) public balances; | ||
uint256 private i_tokensToBeMinted; | ||
|
||
event tokensMinted( | ||
uint256 indexed numberTokensMinted, | ||
address owner | ||
); | ||
|
||
constructor(uint256 tokensToBeMinted) { | ||
balances[tx.origin] = tokensToBeMinted; | ||
i_tokensToBeMinted= tokensToBeMinted; | ||
emit tokensMinted(tokensToBeMinted, msg.sender); | ||
} | ||
mapping(address => uint) public balances; | ||
uint256 private i_tokensToBeMinted; | ||
|
||
function sendCoin(address receiver, uint amount) public returns(bool sufficient) { | ||
if (balances[msg.sender] < amount) { | ||
// return false; | ||
revert SimpleCoin__NotEnoughBalance(); | ||
} | ||
|
||
balances[msg.sender] -= amount; | ||
balances[receiver] += amount; | ||
console.log( | ||
"Transferring from %s to %s %s tokens", | ||
msg.sender, | ||
receiver, | ||
amount | ||
); | ||
return true; | ||
} | ||
event tokensMinted(uint256 indexed numberTokensMinted, address owner); | ||
|
||
function getBalance(address addr) public view returns(uint) { | ||
return balances[addr]; | ||
} | ||
constructor(uint256 tokensToBeMinted) { | ||
balances[tx.origin] = tokensToBeMinted; | ||
i_tokensToBeMinted = tokensToBeMinted; | ||
emit tokensMinted(tokensToBeMinted, msg.sender); | ||
} | ||
|
||
function getMintedTokenBalance() public view returns(uint256){ | ||
return i_tokensToBeMinted; | ||
function sendCoin(address receiver, uint amount) public returns (bool sufficient) { | ||
if (balances[msg.sender] < amount) { | ||
// return false; | ||
revert SimpleCoin__NotEnoughBalance(); | ||
} | ||
} | ||
|
||
balances[msg.sender] -= amount; | ||
balances[receiver] += amount; | ||
console.log("Transferring from %s to %s %s tokens", msg.sender, receiver, amount); | ||
return true; | ||
} | ||
|
||
function getBalance(address addr) public view returns (uint) { | ||
return balances[addr]; | ||
} | ||
|
||
function getMintedTokenBalance() public view returns (uint256) { | ||
return i_tokensToBeMinted; | ||
} | ||
} |
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
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
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
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
File renamed without changes.
Oops, something went wrong.