Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
Last active September 9, 2017 14:48
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 jacqueswww/c7df86eeadb97a3df7414e9b6d5b6ddf to your computer and use it in GitHub Desktop.
Save jacqueswww/c7df86eeadb97a3df7414e9b6d5b6ddf to your computer and use it in GitHub Desktop.
Attempt at translating MyToken example to viper.
# Viper Port of MyToken
# Originally found at https://www.ethereum.org/token
# Public variables of the token
name: public(bytes32)
symbol: public(bytes32)
totalSupply: public(num)
decimals: public(num)
balanceOf: public(num256[address])
def __init__(
_name: bytes32, _symbol: bytes32, _decimals: num, initialSupply: num):
self.name = _name
self.symbol = _symbol
self.decimals = _decimals
self.totalSupply = initialSupply
self.balanceOf[msg.sender] = initialSupply
# Send `_value` tokens to `_to` from your account
def transfer(_to: address, _value: num256):
assert self.balanceOf[msg.sender] > _value
assert self.balanceOf[_to] + _value > self.balanceOf[_to]
self.balanceOf[msg.sender] -= _value # Subtract from the sender
self.balanceOf[_to] += _value # Add the same to the recipient
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment