Created
April 25, 2018 02:42
-
-
Save klawingco/e20c397456274bce29ffb09f6aec7c61 to your computer and use it in GitHub Desktop.
A Sample Wallet Contract Using Solidity (Tested in Ropsen Network / Metamask)
This file contains hidden or 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.4.0; | |
| contract KengCoins | |
| { | |
| //Address of the Coin Creator | |
| address public ico_owner; | |
| struct WalletHolder | |
| { | |
| bytes16 fname; | |
| bytes16 lname; | |
| uint balance; | |
| } | |
| mapping (address => WalletHolder) public WalletHolders; | |
| constructor() public { | |
| ico_owner = msg.sender; | |
| } | |
| //makes sure that the coin creator is the one who'll be able to access methods | |
| //that has this modifier | |
| modifier onlyCreator | |
| { | |
| require(msg.sender == ico_owner); | |
| _; | |
| } | |
| event CoinCreated(address creator, address receiver, uint amount); | |
| event CoinTransferred(address sender, address receiver, uint amount); | |
| function CreateCoins(address receiver, uint amount) onlyCreator public | |
| { | |
| WalletHolders[receiver].balance += amount; | |
| } | |
| function TransferCoins(address receiver, uint amount) public | |
| { | |
| require(WalletHolders[msg.sender].balance < amount ); | |
| //Deduct the amount in sender's balance | |
| WalletHolders[msg.sender].balance -= amount; | |
| //Add the amount in receiver's balance | |
| WalletHolders[receiver].balance += amount; | |
| emit CoinTransferred(msg.sender, receiver, amount); | |
| } | |
| } | |
| contract KengCoinHolder is KengCoins | |
| { | |
| function getWalletInfo(address holder) public constant returns (bytes16,bytes16, uint) | |
| { | |
| return (WalletHolders[holder].fname, | |
| WalletHolders[holder].lname, | |
| WalletHolders[holder].balance); | |
| } | |
| function setWalletInfo(bytes16 fname, bytes16 lname) public | |
| { | |
| WalletHolders[msg.sender].fname = fname; | |
| WalletHolders[msg.sender].lname = lname; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment