sábado, 4 de octubre de 2014

Prototype TimeBank on ethereum

This is a prototype mutual credit system created on ethereum.
The units are expressed in HOURS, like in TimeBanks
  • It has no credit limit. If you want to establish a credit limit, you need to add a line on the serpent code to put this limit.
  • Anyone can participate. If you want to establish a filter to members of a certain association you would need to create a Name Register and filter transactions accordingly.
Instructions:
  1. Download and install ethereum alethzero client cpp-ethereum-PoC6 
  2. Create the contract written on serpent with the code below
  3. Create the HTML page with the code bellow. Run it on the alethzero client
Serpent code
init:
    contract.storage[((msg.sender * 0x10) + 0x1)] = 0x1
    contract.storage[((msg.sender * 0x10) + 0x2)] = 0x1
code:
    toAsset = (msg.data[0] * 0x10) + 0x1
    toDebt = (msg.data[0] * 0x10) + 0x2
    fromAsset = (msg.sender * 0x10) + 0x1
    fromDebt = (msg.sender * 0x10) + 0x2
    value = msg.data[1]
    if contract.storage[fromAsset] >= value:
        contract.storage[fromAsset] = contract.storage[fromAsset]  - value   
    else:
        contract.storage[fromDebt] = value - contract.storage[fromAsset]
        contract.storage[fromAsset] = 0
    if contract.storage[toDebt] >= value:
        contract.storage[toDebt] = contract.storage[toDebt] - value
    else:
        value = value - contract.storage[toDebt]   
        contract.storage[toAsset] = contract.storage[toAsset] + value
        contract.storage[toDebt] = 0
 HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Hours</title>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js">
  <script type="text/javascript">
  //change this contract address to the one you have created!
  var contractAddress = "0x022a6ef6cbbd383073c2c50feccc9565bd2c8da8"
  var assetFrom = eth.secretToAddress(eth.key) + 1
  var debtFrom = eth.secretToAddress(eth.key) + 2      
  function createTransaction() {
    var receiverAddress = '0x' + document.querySelector("#receiverAddress").value;
    var amount = document.querySelector("#amount").value
    var data = eth.pad(receiverAddress, 32) + eth.pad(amount, 32);
    eth.transact({from: eth.key, value: 0, to: contractAddress, data: data, gas: 5000, gasPrice: 100000}, function() {})
  }
  eth.watch({altered: {at: eth.secretToAddress(eth.key), id: contractAddress}}).changed(function() {
    document.getElementById("contractAddress").innerText = contractAddress
    document.getElementById("assetfrom").innerText = assetFrom
    document.getElementById("debtfrom").innerText = debtFrom
    document.getElementById("asset").innerText = eth.toDecimal(eth.stateAt(contractAddress, assetFrom))
    document.getElementById("debt").innerText = eth.toDecimal(eth.stateAt(contractAddress, debtFrom))
      });
   </script>
</head>
<body>
  <div class="header">
    <h2 class="text-muted">Hours <img src="https://sites.google.com/site/desperadostheory/files/hour.png" width="100" /></h2>
    Contract: <strong id="contractAddress"></strong>
  </div>
  <div class="jumbotron">
      Assets Account: <strong id="assetfrom"></strong><br/>
      Assets: <strong id="asset"></strong> HRS<br/>
      Debts Account: <strong id="debtfrom"></strong><br/>
      Debt: <strong id="debt"></strong> HRS<br/>
    <br>
    <div>
      <div class="form-group">
        <input id="receiverAddress" class="form-control" type="text" placeholder="Receiver address"></input><br>
        <input id="amount" class="form-control" type="text" placeholder="Amount"></input><br>
      </div>
      <button class="btn btn-default" onclick="createTransaction();">Send!</button>
    </div>
  </div>
</body>
</html>
Screenshot



3 comentarios:

  1. I am earning 0.00003BTC on my each referral, you can too. Join #XRDICO with my referral id - https://ripplebyte.io/r?ref=XRD839UAOUGNRR #XRDICO #Ripplebyte #Tokensale #BTC #XRD

    ResponderEliminar
  2. At present, cryptocurrency has grown exponentially because of its attractiveness to people looking to use this alternative money. The buzz of virtual currency is all around, people started accepting cryptos for the daily expenses. Here you may see list of cryptocurrencies

    ResponderEliminar
  3. Playtech announces launch of casino app - JTM Hub
    As part of the new initiative, Playtech has released its new 광양 출장샵 software, 대전광역 출장안마 Casino App & Mobile - 삼척 출장안마 Casino.com - a free 하남 출장샵 mobile and 광주 출장마사지 app-based casino

    ResponderEliminar