Example contracts

wemeetagainwemeetagain Posts: 30Member
edited March 2014 in Smart Contracts and Dapps
For me, examples are always very helpful. I feel like I haven't seen that many contract examples...
Lets try to make some basic examples.

I'll start.

A nameserver, where only the sender can edit the data created by that sender:

// input: tx.data[0] = name, tx.data[1] = name data
// stores: key: name, value: [owner address, name data]

// if the fee isn't large enough to run the contract, stop
if tx.value < 100 * block.basefee:
// if the name can overwrite the contract code, stop
if tx.data[0] < 100:
// if name already exists and the sender isn't the name owner, stop
if contract.storage[tx.data[0]]:
if contract.storage[tx.data[0]][0] != tx.sender:
// set name owner and associated data
a = array()
a[0] = tx.sender
a[1] = tx.data[1]
contract.storage[tx.data[0]] = a
Post edited by wemeetagain on


Sign In or Register to comment.