Skip to content

Instantly share code, notes, and snippets.

@kennethhutw
Created April 26, 2023 07:40
Show Gist options
  • Save kennethhutw/d29a5441e9cec8da180943d9f94c60ad to your computer and use it in GitHub Desktop.
Save kennethhutw/d29a5441e9cec8da180943d9f94c60ad to your computer and use it in GitHub Desktop.
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