Giter Club home page Giter Club logo

Blockchain Smart Contract & IPFS - Boilerplate

This helpful Boilerplates that allow you to focus on what makes your DApp unique; includes Solidity Smart Contracts & Libraries, Front-end Views and more.

NPM Package Build Status

Demo

App Ganache Port UI Port
Digital Identity 8545 3333
Flight Delay 8546 3332
Dapp 8547 3331

1. Roadmap

1.1. Truffle Developer

  • O2OProtocol Initial - User Registry Smart Contract
  • Development & Deployment Environment: local,ropsten,rinkeby,mainnet
  • Standard EIP-20: ERC-20 Token Standard. TODO: ERC-233
  • Coding best practices: safeMath
  • Design Pattern: Owned, Controller, Access Controll, Database, Ledger, Oraclize
  • Design Pattern: New Policy, Underwrite, Payout
  • Design Pattern Sharing Economy: Listing, Purchase
  • IPFS
  • Web3 and JSON RPC
  • O2O High-Level Architecture
  • The ABI definition of the Smart Contract: "public" via etherscan + "private" via frontend.
  • Testing using Ganache (TestRPC)
  • servives/src/index.js --> o2oprotocol.js: listings, contractService, userRegistryService, ipfsService.

1.2. Lazy Developer

  • Private Blockchains “Consortium Blockchains” using Geth to setup a “private” or “testnet” Ethereum blockchain. Note: Geth is suitable for building frontends for DApps --> Genesis block, Indentity, DataDir --> Externally Owned Accounts EOA & Contract Accounts TODO
  • Develop eConomySharing: Listing.sol
  • Financial atomic processes & standards: payments, assets, data, identity, KYC, governance

1.3. Happy User

2. Directory Structure

  contracts
  ├── contracts                                           <- Solidity contracts 
  ├── migrations                                            <- Deployment Script
  ├── test                                                  <- Test contracts
  ├── truffle-config.js                                     <- Truffle config
  src                                                     <- O2O Service
  ├── ipfs-service                                          <- IPFS service
  ├── contract-service                                      <- Contract service
  ├── test                                                  <- Test services
  README.md

3. Tests

Browser tests are automatically served at http://localhost:8081 when you run npm start.

Tests are automatically rerun when source or test code is changed.

Run a subset of tests using the grep query string parameter, for example: http://localhost:8081/?grep=IpfsService

We also have contract unit tests that are not run in the browser. These can be run with npm run test:contracts (you should not have the server running at this time, as these tests start their own local blockchain instance).

O2OProtocol JS Documentation

Introduction

Welcome to the o2oprotocol.js documentation! o2oprotocol.js is a Javascript library for interacting with the O2O Protocol. Using the library you can create new listings from your applications, purchase them, or update them from your own off-chain applications.

More information can be found at O2OProtocol Platform Readme

Warning

This is still an alpha version which will evolve significantly before the main net release.

Data Sharing

Sellers:

  • Create Listings
  • Update Listings
  • Delete Listings
  • Validate Listings

Buyers:

  • Browse Listing
  • Create Bookings
  • Update Bookings
  • Cancel Bookings

Note: to show the gas costs of each transaction during a test, set the enviroment variable GAS_TRACKING before launching truffle develop. For example, using bash: GAS_TRACKING=1 npx truffle develop

Install

NPM

npm install o2oprotocol --save

Yarn

yarn add o2oprotocol

Local

For developing on o2oprotocol.js, it is better to link the package rather than installing it. (Otherwise you would need to run npm build everytime you made a change to the package.)

Install:dev (shortcut for npm install && npm link). Linking makes this available as a local npm package for local dapp development

npm run install:dev

Import

import O2OProtocol from 'o2oprotocol'
const configOptions = {}
const { contractService, ipfsService, o2oService } = new O2OProtocol(configOptions)

Configuration Options

Config options are passed into the O2OProtocol constructor at instantiation

const configOptions = {
  option: 'value'
}
const o2o = new O2OProtocol(configOptions)

Valid options:

  • ipfsDomain
  • ipfsApiPort
  • ipfsGatewayPort
  • ipfsGatewayProtocol
  • attestationServerUrl

IPFS

If you are running a local IPFS daemon then set the following config options (see config options):

{
 ipfsDomain: '127.0.0.1',
 ipfsApiPort: '5001',
 ipfsGatewayPort: '8081',
 ipfsGatewayProtocol: 'http'
}

Configure your local IPFS daemon with the following settings to avoid CORS errors:

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["localhost:*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'

Troubleshooting

Python 3

If you have Python 3 installed, you may see this error when installing dependencies:

gyp ERR! stack Error: Python executable "/Users/aiham/.pyenv/shims/python" is v3.6.4, which is not supported by gyp.

Resolve this by configuring npm to use Python 2 (where python2.7 is a binary accessible from your $PATH):

npm config set python python2.7

Tests

When you begin developing, run npm test and keep it running while you develop.

View test results in your browser (with MetaMask installed and setup) at http://localhost:8081

Tests are automatically rerun when source or test code is changed.

Run a subset of tests using the grep query string parameter, for example: http://localhost:8081/?grep=IpfsService

Discussion

Smart Contract Audit

  • Unit tests passing, checking tests configuration (matching the configuration of main network);
  • Compilator warnings;
  • Race Conditions. Reentrancy. Cross-function Race Conditions. Pitfalls in Race Condition solutions;
  • Possible delays in data delivery;
  • Transaction-Ordering Dependence (front running);
  • Timestamp Dependence;
  • Integer Overflow and Underflow;
  • DoS with (unexpected) Revert;
  • DoS with Block Gas Limit;
  • Call Depth Attack. Not relevant in modern ethereum network :)
  • Methods execution permissions;
  • Oracles calls;
  • Economy model. It’s important to forecast scenarios when user is provided with additional economic motivation or faced with limitations. If application logic is based on incorrect economy model, the application would not function correctly and participants would incur financial losses. This type of issue is most often found in bonus rewards systems.
  • The impact of the exchange rate on the logic;
  • Private user data leaks. Needed

O2OProtocol Services

  • package.json

    • "form-data": "^2.3.2",
    • "ipfs-api": "^14.3.7",
  • actual gas cost by running web3.eth.getTransactionReceipt(txId)

  • Store IPFS and contract data separately

  • the upcoming version of web3 will work with truffle

  • Return custom objects instead of raw web3 transactions from API

  • Move logic out of Listing contract

  • Discussion around how to do smart contract migrations

  • Listings expire 60 days after creation.

  • there are six events that affect transaction state, each caused by the action of a sole party, and two of them (5 & 6) being potentionally out of sequence:

Create listing (seller) Buy listing (buyer) - presumed to be the equivalent of sending money Fulfill order (seller) Receive order (buyer) Withdraw funds (seller) Provide feedback (buyer)

  • Data verification for JSON schema listings

O2O Protocol's Projects

dapp-boilerplate icon dapp-boilerplate

DApp Boilerplate for Ethereum DApp, built on React, Truffle 4, and O2O Blockchain Protocol.

o2obnb icon o2obnb

Blockchain-based AirBnB Marketplace to reinventing the Home Sharing Economy by building a middleman free, peer-to-peer network of hosts and guests on the decentralized web.

o2omall icon o2omall

O2O Mall - Online to Offline Marketplace SaaS Platform using Chatbot & Blockchain Technology

s3-bnb-serverless icon s3-bnb-serverless

Open guideline for building and deploying full-stack apps using Serverless and React on AWS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.