Subcurrency in Serpent

Loading...
init:
    # Initial: premine 1000000 units to creator
    contract.storage[msg.sender] = 1000000
code:
    # If a message with one item is sent, that's a balance query
    if msg.datasize == 1:
        addr = msg.data[0]
        return(contract.storage[addr])
    # If a message with two items [to, value] are sent, that's a transfer request
    else:
        from = msg.sender
        fromvalue = contract.storage[from]
        to = msg.data[0]
        value = msg.data[1]
        if fromvalue >= value:
            contract.storage[from] = fromvalue - value
            contract.storage[to] = contract.storage[to] + value
            return(1)
        else:
            return(0)

Serpent contract for Ethereum

Subcurrency in Serpent

GitHub

Preferences

Note: Your changes won't be saved, because not Logged-in.

Create your own Contract