Drupal Ethereum Module

#DrupalEthereum @digitaldonkey09

Overview

  • Blockchain & Ethereum building blocks
  • Applications
  • Ethereum Module

About me

  • 20 years ​​web development  
  • 10+ years with Drupal
  • 3+ years in Ethereum 
  • Developer at ConsenSys 

@digitaldonkey09

Blockchain Basics

Blockchain's promises

"Sharing Economy" of
Uber, Airbnb

Centralized user data,
siloed Facebook, Google

Peer to Peer
+ no middlemen

Self-sovereign
user data

Internet of
Information

Crypto enthusiasts see the new layer of trust and value as Web3.0

Internet of
Value

"Ethereum is an open-source,
 public, blockchain-based
 distributed computing
 platform featuring smart
 contract functionality"

Ethereum Blockchain

Programmable
money:
Smart Contracts

Decentralized
P2P Network

 

Immutable Global Ledger

 

Cryptographically signed updates

Consensus
 without a central authority

Censorship-resistant

Public-Private Keys

Native token as currency

Ethereum - Global or Private

Private Consortium
Blockchain
(permissions, privacy, speed)

 

Global Public
Blockchain

BLOCKCHAIN

Timestamps

Currency

Digital Signatures

Accounts

Immutable Ledger

Blockchain Accounts

  • Account Address derived from private key
    (independent from the network)
     
  • Accounts exist on chain only after sending / receiving a transaction

BLOCKCHAIN

Timestamps

Currency

Digital Signatures

Accounts

Immutable Ledger

  • Transactions cost "gas" per computation step and for storage
     
  • Prevents spam
     
  • Pays "miners" to run peer nodes

Transactions

Transaction

Transactions, Blocks & Chaining

  • "Writes" to blockchain require private key to sign transactions
     
  • Blocks
    • contain hash of last block
    • created every ~14 seconds in Ethereum

time

Miners compete to compute next block to earn Gas

BLOCKCHAIN

Timestamps

Currency

Signatures

Accounts

Ledger

Smart Contracts

  • Run automatically when certain conditions are met
     
  • Can send/receive funds like accounts
     
  • Have address like accounts
contract CrowdFund
 if time_is_up && balance > $10,000
   move balance to crowdfund_account
 else
   return donation to original_donor

(pseudocode)

are programs with code and state stored on the blockchain

Smart Contracts

ETHEREUM

Timestamps

Currency

Signatures

Accounts

Ledger

Smart Contracts

Registries

  • Maps data to an address e.g. an owner
  • Programmatically an array stored in a smart contract
  • Can define permissions, ownership, tokes etc...
  • Ethereum Name Service (ENS) maps something.eth => address

Registries

ETHEREUM

Timestamps

Currency

Signatures

Accounts

Ledger

Smart Contracts

Registries

Multi-party Signatures

  • Multiple account holders can sign
     
  • Safety for spending large amts or key recovery

Multi sig Wallets

ETHEREUM

Timestamps

Currency

Signatures

Accounts

Ledger

Smart Contracts

Registries

Multi-party Signatures

Tokens

ERC-20 Tokens
fungible (replaceable) tradable assets (a banknote, stock)

ERC-721 Non-fungible Tokens

unique tradable assets (a Van Gogh painting or CryptoKitty)
Categories of Tokens
payment tokens, investment tokens, consumer utility tokens

Tokens

ETHEREUM

Timestamps

Currency

Signatures

Accounts

Ledger

Smart Contracts

Registries

Multi-party Signatures

Tokens

Oracles

Oracles

  • Real world data to use in smart contracts

  • Input must be agreed to, trustworthy, multiple sources
  • e.g. current price of X, location of Y

off-chain input

Ethereum Community

COMMUNITY
CREATING
STANDARDS

Blockchain
Applications

Blockchain Applications

Industry & Finance

  • Money transfer, micropayment, paywalls
  • Decentralized exchanges, finance, stable coins
  • Supplychain asset tracking
  • Digital assets, licensing (music, images, video)
  • Incentivized content (media)
  • Shared ownership (asset tokens)

https://www.eublockchainforum.eu/noteworthy/articles

Public & Social Services

  • Community currencies
  • Digital signatures
  • Public registries (land registries, DNS, identity)
  • Decentralized governance, voting, budgeting

Subscription Model

ERC-948 Recurring Subscription

Subscription smart contract

  • User consents to funds withdrawn every time_period by service_address
  • User can remove consent at any time
  • Provider of service_address may remove funds every time_period if tokens are available and time_period has passed since last withdrawal

User

Provider

?

Digital Identity Today

Is proprietary / Isn't self owned

  • Facebook / Google 
  • Credit cards, Bank accounts
  • Equifax -> Random hackers
  • State IDs / Passports

You pay for your "free" online identity with privacy

You can be excluded ("You may leave if you don't like the new Terms & Conditions")

Self Sovereign Identity

Portable Decentralized identifier (DID)

  • You create a claim:
    "My address is 1 Metropolitan Av, Brooklyn"
  • Others attest your claim:
    "New York State verifies person registered at this address with the official NYS signature"
  • As a developer you would chose which attestations you consider trustworthy
  • In the long run Drupal might use DID data or verify claims of users

Asset tokenization
sharing + incentives

  • Tokenize a tractor in a crowd sale
  • Agree on rules of usage e.g. A tractor-token holder:
    • gets 100 tuktuk-tokens per year
    • can buy tractor-time by placing tuktuk-tokens on its calendar
    • can trade tuktuk-tokens with other tractor token holders
    • can rent out the tractor and vote how to spend funds
  • community incentivized to keep tractor tokens valuable and tractor in good shape

Drupal Ethereum Module

Drupal Ethereum Module
Overview

  • Semi-decentralized Architecture
  • Ethereum PHP library
  • Ethereum Sign-up 
  • Ethereum User Connector - registry contract
  • Frontend UX challenges
  • ​Managing smart contracts & event triggers

Launch example site using Docker

https://github.com/digitaldonkey/docker-drupal-ethereum

Development goals

Framework to develop Ethereum applications with Drupal

Ready for pioneers to get started

Frontend agnostic

     many wallets and signing tools

Goal is out-of-the-box modules + good use cases

Backend agnostic

     work with any Ethereum client or service

Semi-decentralized

     Ethereum decentralized apps (dapps) are on a hard UX road to serverless

Current Web

Ideal Decentralization

How to connect Drupal and Ethereum?

Semi-decentralization

Client side signing using Transaction-signers

Server just pulls data from blockchain

Architecture challenges

Transaction Signers
Javascript API

Drupal

Ethereum PHP
library

Ethereum Clients or Services

Ethereum

Push Transaction
Independently

Infura.io API

Etherscan API

Ethereum Nodes

Other providers

Ethereum-PHP Library

  • Abstracts the Ethereum JSON RPC API
  • strict Datatypes, Cryptographic functions
  • SmartContract Objects
  • Contract Event decoding
  • Testing against smart contracts

Ethereum Nodes

https://github.com/digitaldonkey/ethereum-php

API documentation:    http://ethereum-php.org

Mapping Ethereum to Drupal

Infrastructure modules

Accounts
Map Accounts/Addresses to Drupal Accounts
➡ "Ethereum Identity for a known user group"
Experiment on connecting identity
Ethereum Signup / Ethereum User Register

Smart Contracts

Manage deploy as Drupal Admin

Provide ABI to process data in Drupal & frontend

Let Blockchain Events trigger PHP actions

Ethereum Smart Contract Entity

Servers (Ethereum Nodes)

Manage and Connect to Ethereum-nodes
Manage Networks IDs
Server Status Page

Ethereum main module
 

Transactions Signing

Provide contract ABI in frontend and Web3js

Let Drupal know about Blockchain actions

Provide default UI and web3Ready() in front end
Transaction Signers (web3)

Two Signup modules?

Ethereum Signup

  • Challenge/response authentication
  • No blockchain interaction - no gas
  • Just private-public keys
  • Uses external auth module

Ethereum User Connector

  • Smart contract with User Registry
  • Can be changed to a paywall
  • Example module for contract interaction

Ethereum Signup

Text

Text + Private Key => Signature
Text + Signature Text  =>  Ethereum Address

Ethereum User Register

Signing Transactions

  • Signing on Frontend
    • Literally the key in the user's hand
    • UX challenges
    • lost keys are lost forever
  • Signing on PHP backend
    • Hosting private keys turns your server into a honey pot
    • multi-sig contracts can help secure

Popular Tools

private key UX is hard​

Browser Extensions

Hardware Wallets

Mobile Wallets & Signers

Desktop Wallets

Cloud Wallets

"Web of wallets"

by Bobby Dresser (uPort)

Web3 browser wars?

The Front-end challenge

  • How to help users not lose their key?
  • Deal with Identity proxy contracts
  • Integrate multiple wallets
     ⇢ allow users to chose, increase browser support
  • Is the user/wallet on the right network?
  • Unlocked account required?
  • How to onboard new users, which have no wallet?

    ⇢ Experiment with UX interactions
    ⇢ Develop standards for Dapp interaction

Transaction signer module

  • Loading TX-signers config based to allow:
    • experimentation on different approaches
    • define different security levels based on use case
  • ​Abstract and unify Ethereum UX
  • Provide a minimal API for Frontend development
  • Currently one TX signer "Mascara"

Experimental
Mascara & Dapp launcher

Visualize TX signer state 

Initialize dapplet when requirements are met

  • Manage Contracts in Drupal 
  • Provide Contract ABI for frontend and Backend
  • Handle Contract Events
  • Import from Truffle

Smart contract Module

Listening to Blockchain state change in PHP

  • web3.eth.subscribe() and web3.eth.filter() are not consistently implemented/accessible
  • Process all Blocks with cronjob and process relevant Events
  • GraphQL solution (query language as API) https://github.com/ConsenSys/ethql
  • Currently: Frontend transaction-hash-ajax solution

 

Smart contract EventProcessor

Smart contract Event
processor flowchart

What?

  1. Emit an Event in you Solidity contract code e.g in RegisterDrupal->newUser()
     

  2. Add a "on"-EventHandler in your module src/Plugin/SmartContract





                                           ethereum_user_connector/src/Plugin/SmartContract/RegisterDrupal.php

  3. Trigger a web3 action like this.contract.methods.newUser(...)

  4. Submit transaction hash to Drupal.behaviors.txHash.submit(TxHash, callback)
  5. Handle response feedback in javascript callback()
  class RegisterDrupal extends SmartContract {
    public static function onAccountCreated(EmittedEvent $event) {
      $hash = $event->getData()['hash'];
      $event->setResponse($controller>verifyUserByHash($hash));
    }
  }
  emit AccountCreated(msg.sender, hash);

Architecture summary

Roadmap

  • Explore and improve UX / frontend TX signers
  • PHP based backend signing
  • Asset tokenisation
  • Field formatter for Contract import/deployment from Drupal
  • Contract events ---> Rules actions? 
  • EIP-948 reoccurring subscriptions
  • DID based on W3C spec https://w3c-ccg.github.io/did-spec
  • Cron and batch indexing Transactions (to TX entities?)

    --> A lot to do. Priorities based on engagement

Drupal Ethereum module

Tools to start developing

  • PHP 7.2 and GMP required by Ethereum-PHP library
  • Frontend coding: Node.js and ES7 with browserify
  • Smart Contract development
    • Solidity programming language
    • Truffle suite 
    • Remix Solidity online http://remix.ethereum.org
  • Blockchains
    • Ganache Test chain with Blockexplorer
      https://truffleframework.com/ganache
    • Infura.io Blockchain as a Service
  • Blockchain explorer https://etherscan.io

Lots of Thanks to early
contributors & testers

so far 27 pull requests merged

(Commits/PRs stats refer to the various involved projects and may not be up to date)

Questions & Thank You

  • Tweet about #DrupalEthereum
  • Run an example https://github.com/digitaldonkey/docker-drupal-ethereum
  • BOF: Wednesday 11:30-12:15 2.08 platinum
  • Join discussion, contribute and ★ repos on Github
    https://github.com/digitaldonkey/ethereum

thorsten.krug@consensys.net
       @digitaldonkey09

The development of Drupal Ethereum Module
Has been sponsored by ConsenSys

       @ConsenSys

https://consensys.net

https://slides.com/digitaldonkey/drupaleurope

Drupal Ethereum

By Thorsten Krug

Drupal Ethereum

Presentation about Drupal Ethereum module at Drupal Erupe conference 2018

  • 557
Loading comments...

More from Thorsten Krug