├── DataWallet.ipynb ├── README.md └── safe_remote_purchase.sol /DataWallet.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## What is DataWallet? \n", 8 | "\n", 9 | "![alt text](https://i2.wp.com/coinfunda.com/wp-content/uploads/2017/12/DataWallet-App.png?ssl=1 \"Logo Title Text 1\")\n", 10 | "\n", 11 | "- A blockchain-based data-exchange that allows users to earn a passive income from their data\n", 12 | "- Users get rewarded either via the proprietary network token (DXT) or via personalized services\n", 13 | "- It gives users complete ownership over their own data, while giving developers and data consumers access to a marketplace for high-quality data. \n", 14 | "- Data consumers use data exchange tokens (DXT) to purchase data directly from creators using a smart contract which ensures security and transparency from both parties. \n", 15 | "- It also provides a data API to enables developers to use this data to build apps.\n", 16 | "\n", 17 | "## Why is it Useful? \n", 18 | "\n", 19 | "![alt text](https://lh4.googleusercontent.com/oDnoAiArLVDCG8IFnnPgoNxZE153UpGRfkVJGAfW6lAXkmoVeG1opv_8AODMKn0IHRpt-B6ZrbLYfWizTCSP0oignkOcwzT1KnvCG7QClG7D4bwwGW-jRpaLfv4vX3FIzeVBh4bE=w1200-h630-p-k-no-nu \"Logo Title Text 1\")\n", 20 | "\n", 21 | "- 90% of the world's data has been generated in the past 2 years. Thats a lot of data! We need a new business model\n", 22 | "- Data generated through your use of social media and other online platforms are currently controlled by those companies\n", 23 | "- DataWallet lets you share data as you wish and earn money from it.\n", 24 | "- A Datawallet profile gives you data mobility, allowing you to easily plug into any AI-powered app and get personalized services.\n", 25 | "- It allows you to trade anonymized parts of your data to businesses or developers who list contract offers. \n", 26 | "- Contracts specify the type of data it will collect and the benefit offered, namely Datawallet’s data exchange token DXT. Datawallet will provide payout options\n", 27 | "- User data production is fragmented across different platforms, Data Brokers must employ probabilistic models to approximate the likelihood of data points belonging to a given user. These highly fallible models lead to misunderstanding of target audiences.\n", 28 | "\n", 29 | "## Applications\n", 30 | "\n", 31 | "![alt text](https://image.slidesharecdn.com/marketingresearchch5malhotra-140725014700-phpapp02/95/marketing-research-ch-5malhotra-6-638.jpg?cb=1406252902 \"Logo Title Text 1\")\n", 32 | "\n", 33 | "- Market Research- It allows for entirely automated data capture which eradicates the biases associated with traditional surveying techniques. \n", 34 | "- Deterministic Advertising- Advertisers can deterministically find the right target customers based on verifiable historic as well as real-time social media and purchase data. \n", 35 | "- Personalized Car Insurance - A user’s collated data wallet is exactly what Auto insurers are looking for\n", 36 | "- Personalized Loan Underwriting - lenders are always searching for ways to more accurately determine a borrower’s probability of defaulting.\n", 37 | "- Psychographic Hiring - A digitally interpretable collation of an applicant’s experiences, talents, and personality (their data)\n", 38 | "\n", 39 | "## Tech Stack\n", 40 | "\n", 41 | "![alt text](https://i0.wp.com/globalhalo.com/wp-content/uploads/2018/01/datawallet.jpg?resize=720%2C368&ssl=1 \"Logo Title Text 1\")\n", 42 | "\n", 43 | "![alt text](https://www.2ndquadrant.com/media/filer_public_thumbnails/filer_public/a8/54/a854c5d1-82cd-47a8-83bf-6838aa6d762d/postgres-xl_display.png__650x465_q85_subsampling-2.png \"Logo Title Text 1\")\n", 44 | "\n", 45 | "Databases:\n", 46 | "- API usage: POSTGRESQL + REDIS\n", 47 | "- Pipeline usage: AURORA\n", 48 | "Languages:\n", 49 | "- Front-end: Javascript ES2018 via babel. Swift 4, Java8\n", 50 | "- Back-end: Node LTE, Python 3, Golang\n", 51 | "Infrastructure:\n", 52 | "- Front-end: Cloudfront + S3\n", 53 | "- Back-end: Scaling groups + EC2 + ELB\n", 54 | "- Monitoring: Cloudwatch\n", 55 | "- Deployment: Terraform\n", 56 | "- Blockchain: Ethereum \n", 57 | "\n", 58 | "![alt text](https://cdn-images-1.medium.com/max/1600/0*B_K9HNktRm_DrEZT.png \"Logo Title Text 1\")\n", 59 | "\n", 60 | "\n", 61 | "## Solidity Example of exchange contract \n", 62 | "\n", 63 | "```\n", 64 | "pragma solidity ^0.4.21;\n", 65 | "\n", 66 | "contract Purchase {\n", 67 | " uint public value;\n", 68 | " address public seller;\n", 69 | " address public buyer;\n", 70 | " enum State { Created, Locked, Inactive }\n", 71 | " State public state;\n", 72 | "\n", 73 | " // Ensure that `msg.value` is an even number.\n", 74 | " // Division will truncate if it is an odd number.\n", 75 | " // Check via multiplication that it wasn't an odd number.\n", 76 | " function Purchase() public payable {\n", 77 | " seller = msg.sender;\n", 78 | " value = msg.value / 2;\n", 79 | " require((2 * value) == msg.value);\n", 80 | " }\n", 81 | "\n", 82 | " modifier condition(bool _condition) {\n", 83 | " require(_condition);\n", 84 | " _;\n", 85 | " }\n", 86 | "\n", 87 | " modifier onlyBuyer() {\n", 88 | " require(msg.sender == buyer);\n", 89 | " _;\n", 90 | " }\n", 91 | "\n", 92 | " modifier onlySeller() {\n", 93 | " require(msg.sender == seller);\n", 94 | " _;\n", 95 | " }\n", 96 | "\n", 97 | " modifier inState(State _state) {\n", 98 | " require(state == _state);\n", 99 | " _;\n", 100 | " }\n", 101 | "\n", 102 | " event Aborted();\n", 103 | " event PurchaseConfirmed();\n", 104 | " event ItemReceived();\n", 105 | "\n", 106 | " /// Abort the purchase and reclaim the ether.\n", 107 | " /// Can only be called by the seller before\n", 108 | " /// the contract is locked.\n", 109 | " function abort()\n", 110 | " public\n", 111 | " onlySeller\n", 112 | " inState(State.Created)\n", 113 | " {\n", 114 | " emit Aborted();\n", 115 | " state = State.Inactive;\n", 116 | " seller.transfer(this.balance);\n", 117 | " }\n", 118 | "\n", 119 | " /// Confirm the purchase as buyer.\n", 120 | " /// Transaction has to include `2 * value` ether.\n", 121 | " /// The ether will be locked until confirmReceived\n", 122 | " /// is called.\n", 123 | " function confirmPurchase()\n", 124 | " public\n", 125 | " inState(State.Created)\n", 126 | " condition(msg.value == (2 * value))\n", 127 | " payable\n", 128 | " {\n", 129 | " emit PurchaseConfirmed();\n", 130 | " buyer = msg.sender;\n", 131 | " state = State.Locked;\n", 132 | " }\n", 133 | "\n", 134 | " /// Confirm that you (the buyer) received the item.\n", 135 | " /// This will release the locked ether.\n", 136 | " function confirmReceived()\n", 137 | " public\n", 138 | " onlyBuyer\n", 139 | " inState(State.Locked)\n", 140 | " {\n", 141 | " emit ItemReceived();\n", 142 | " // It is important to change the state first because\n", 143 | " // otherwise, the contracts called using `send` below\n", 144 | " // can call in again here.\n", 145 | " state = State.Inactive;\n", 146 | "\n", 147 | " // NOTE: This actually allows both the buyer and the seller to\n", 148 | " // block the refund - the withdraw pattern should be used.\n", 149 | "\n", 150 | " buyer.transfer(value);\n", 151 | " seller.transfer(this.balance);\n", 152 | " }\n", 153 | "}\n", 154 | "```" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [] 163 | } 164 | ], 165 | "metadata": { 166 | "kernelspec": { 167 | "display_name": "Python 3", 168 | "language": "python", 169 | "name": "python3" 170 | }, 171 | "language_info": { 172 | "codemirror_mode": { 173 | "name": "ipython", 174 | "version": 3 175 | }, 176 | "file_extension": ".py", 177 | "mimetype": "text/x-python", 178 | "name": "python", 179 | "nbconvert_exporter": "python", 180 | "pygments_lexer": "ipython3", 181 | "version": "3.6.3" 182 | } 183 | }, 184 | "nbformat": 4, 185 | "nbformat_minor": 2 186 | } 187 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # datawallet 2 | This is the code for "Decentralized Data" By Siraj Raval on Youtube 3 | 4 | ## Overview 5 | 6 | This is the code and slides for [this](https://youtu.be/BQx0NZgLgtU) video on Youtube by Siraj Raval. The code allows two parties to trade with each other without needing an intermediary to trust. 7 | 8 | 9 | ## Instructions 10 | 11 | Run the code in the Ethereum online IDE called Remix -- http://remix.ethereum.org/ 12 | 13 | 14 | ## Credits 15 | 16 | Credits go to the Ethereum Foundation 17 | -------------------------------------------------------------------------------- /safe_remote_purchase.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.21; 2 | 3 | contract Purchase { 4 | uint public value; 5 | address public seller; 6 | address public buyer; 7 | enum State { Created, Locked, Inactive } 8 | State public state; 9 | 10 | // Ensure that `msg.value` is an even number. 11 | // Division will truncate if it is an odd number. 12 | // Check via multiplication that it wasn't an odd number. 13 | function Purchase() public payable { 14 | seller = msg.sender; 15 | value = msg.value / 2; 16 | require((2 * value) == msg.value); 17 | } 18 | 19 | modifier condition(bool _condition) { 20 | require(_condition); 21 | _; 22 | } 23 | 24 | modifier onlyBuyer() { 25 | require(msg.sender == buyer); 26 | _; 27 | } 28 | 29 | modifier onlySeller() { 30 | require(msg.sender == seller); 31 | _; 32 | } 33 | 34 | modifier inState(State _state) { 35 | require(state == _state); 36 | _; 37 | } 38 | 39 | event Aborted(); 40 | event PurchaseConfirmed(); 41 | event ItemReceived(); 42 | 43 | /// Abort the purchase and reclaim the ether. 44 | /// Can only be called by the seller before 45 | /// the contract is locked. 46 | function abort() 47 | public 48 | onlySeller 49 | inState(State.Created) 50 | { 51 | emit Aborted(); 52 | state = State.Inactive; 53 | seller.transfer(this.balance); 54 | } 55 | 56 | /// Confirm the purchase as buyer. 57 | /// Transaction has to include `2 * value` ether. 58 | /// The ether will be locked until confirmReceived 59 | /// is called. 60 | function confirmPurchase() 61 | public 62 | inState(State.Created) 63 | condition(msg.value == (2 * value)) 64 | payable 65 | { 66 | emit PurchaseConfirmed(); 67 | buyer = msg.sender; 68 | state = State.Locked; 69 | } 70 | 71 | /// Confirm that you (the buyer) received the item. 72 | /// This will release the locked ether. 73 | function confirmReceived() 74 | public 75 | onlyBuyer 76 | inState(State.Locked) 77 | { 78 | emit ItemReceived(); 79 | // It is important to change the state first because 80 | // otherwise, the contracts called using `send` below 81 | // can call in again here. 82 | state = State.Inactive; 83 | 84 | // NOTE: This actually allows both the buyer and the seller to 85 | // block the refund - the withdraw pattern should be used. 86 | 87 | buyer.transfer(value); 88 | seller.transfer(this.balance); 89 | } 90 | } 91 | --------------------------------------------------------------------------------