10.02.2016 Views

Bitcoin and Cryptocurrency Technologies

1Qqc4BN

1Qqc4BN

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

written in bytecode <strong>and</strong> executed by a special Ethereum‐specific virtual machine, usually just called<br />

EVM. Once uploaded, the contract will live on the blockchain. It has its own balance of funds, other<br />

users can make procedure calls through whatever API the program exposes, <strong>and</strong> the contract can<br />

send <strong>and</strong> receive money.<br />

A simple example: Namecoin in Ethereum.​We claimed that Ethereum can be used to implement any<br />

application‐specific altcoin’s functionality. As a simple example, we can show how to implement<br />

Namecoin‐style functionality in a very simple Ethereum contract.<br />

One example implementation is shown in Figure 10.8. It is coded in Solidity, Ethereum’s high‐level<br />

programming language for defining contracts. This contract implements a crude name/value store or<br />

name registry, in which names are assigned values once <strong>and</strong> for all. The contract defines a data<br />

variable, registryTable, which is a mapping from 32‐byte strings to public keys. initially, it maps every<br />

string to the null address 0x0000000000...000. This contract also defines a single entry point, called<br />

“claimName”. This entry point accepts a single argument, name. First, the contract makes sure that<br />

the caller has sent a value of at least 10 wei, wei being the smallest currency unit in Ethereum. If<br />

insufficient funds have been sent, the contract terminates with an error (the “throw” statement does<br />

this) <strong>and</strong> no action is taken. If sufficient funds are sent <strong>and</strong> the name is not yet taken, then it is<br />

permanently assigned the value of whichever address invoked this function.<br />

contractNameRegistry{<br />

mapping(bytes32=>address)publicregistryTable;<br />

functionclaimName(bytes32name){<br />

if(msg.value

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!