Created
April 26, 2023 07:40
-
-
Save kennethhutw/d29a5441e9cec8da180943d9f94c60ad 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
pragma solidity ^0.5.0; | |
contract MetaCoin { | |
mapping (address => uint) balances; | |
constructor(address metaCoinOwner, uint256 initialBalance) public { | |
balances[metaCoinOwner] = initialBalance; | |
} | |
function sendCoin(address receiver, uint amount) public returns(bool sufficient) { | |
if (balances[msg.sender] < amount) return false; | |
balances[msg.sender] -= amount; | |
balances[receiver] += amount; | |
return true; | |
} | |
function getBalance(address addr) view public returns(uint) { | |
return balances[addr]; | |
} | |
} | |
contract MetaCoinFactory { | |
MetaCoin[] public metaCoinAddresses; | |
event MetaCoinCreated(MetaCoin metaCoin); | |
address private metaCoinOwner; | |
constructor(address _metaCoinOwner ) public { | |
metaCoinOwner = _metaCoinOwner ; | |
} | |
function createMetaCoin(uint256 initialBalance) external { | |
MetaCoin metaCoin = new MetaCoin(metaCoinOwner, initialBalance); | |
metaCoinAddresses.push(metaCoin); | |
emit MetaCoinCreated(metaCoin); | |
} | |
function getMetaCoins() external view returns (MetaCoin[] memory) { | |
return metaCoinAddresses; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment