Skip to content

Instantly share code, notes, and snippets.

@karthickpdy
Last active September 1, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthickpdy/b077779837d2873167688d89199e2477 to your computer and use it in GitHub Desktop.
Save karthickpdy/b077779837d2873167688d89199e2477 to your computer and use it in GitHub Desktop.
Stock Exchange smart contract
pragma solidity ^0.4.2;
contract StockExchange {
mapping (address => uint) balances;
uint holdings;
event Transaction(string _type, address indexed user);
function StockExchange() {
holdings = 10000;
}
function buy() payable{
if(msg.value == 1 ether){
balances[msg.sender] += 1;
holdings -= 1;
Transaction("Buy",msg.sender);
}
}
function sell(){
balances[msg.sender] -= 1;
holdings += 1;
msg.sender.transfer(1 ether);
Transaction("Sell",msg.sender);
}
function getBalance(address addr) returns(uint) {
return balances[addr];
}
function getHoldings() returns(uint) {
return holdings;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment