ethereum training

Smart Contracts Overview

ethereum POC5 (well, almost...)

ethercasts

Prerequisites

Training Modules

What can you do with smart contracts?

  • Create a Currency
  • Financial Derivatives
  • Savings Wallet
  • Data storage
  • Name Registration
  • Decentralized Organizations

Ethereum Platform

  • Contracts live on the Ethereum block chain
  • Have own Ethereum address and balance
  • Can send and receive transactions
  • "Activated" when you send a transaction to it
  • Turing complete language (~85 opcodes)
  • Executed & verified by all miners
  • Fee per CPU step (extra for storage, tx, crypto)
  • 2^256 Storage entries
  • Contracts can call (and create!) other contracts

Clients

AlethZero

AlethZero

Ethereal

Ethereal

And more..

Languages

EtherScript


TXVALUE PUSH 25 PUSH 10 PUSH 18 EXP MUL LE NOT PUSH 34 JMPI STOP PUSH 34
JMP PUSH 0 TXDATA SLOAD NOT PUSH 0 TXDATA PUSH 1000 LT NOT MUL NOT NOT
PUSH 34 JMPI STOP PUSH 1 TXDATA PUSH 0 TXDATA SSTORE

Serpent: Python Like Language


init:
    contract.storage[msg.sender] = 1000000
code:
    if msg.datasize == 1:
        addr = msg.data[0]
        return(contract.storage[addr])
    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)

LLL: Lisp-Like Language


{
  [0] "Splitter"
  (call (- (gas) 100) 0x2d0aceee7e5ab874e22ccf8d1a649f59106d74e8 0 0 8 0 0)

  (return 0 (lll {
    [count] (/ (calldatasize) 32)
    [pay] (/ (callvalue) @count)

    ;; Cycle through each address
    (for {} (< @i @count) [i](+ @i 1)
      ;; Send to 'i'th argument (assuming it's an address).
      (call (- (gas) 100) (calldataload (* @i 32)) @pay 0 0 0 0)
    )
  } 0))
}

Mutan: Go-Like Language


int32 a = 20
int32 b = 10

var str = "hello"
otherStr := "world"

if a < b {
    exit()
} else {
    // :-)
    if !a {
        if this.data[0] ** 10 >= 10 {
            this.data[0] = 1000;
        }
    }
}

Online Tools

EtherScripter.com

EtherScripter

MintChalk.com

MintChalk

mutan.jeffew.com

Online Mutan Compiler

Online Resources

What's next?

Ethereum Virtual Machine

Questions / Feedback?