No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
smartsuite-dapp-main
smartsuite-next
.DS_Store
.gitignore
README.md

README.md

SmartSuite-Dapp

A dapp for auctioning and investing in fractionla real-estate ownership.

Steps

Initialize truffle

//--------------------------------------------------------------------------------------------------------------------------

Install truffle as a dev dep



==> truffle init

==> npm install --save truffle-hdwallet-provider

==> npm install --save-dev truffle-hdwallet-provider

==> yarn add dotenv

==> npm init -y

==> npm install -g -D truffle

==> npm install -D webpack react react-dom babel-core babel-loader babel-preset-react babel-preset-env css-loader style-loader json-loader web3@0.20.0


==> npm install -g http-server

//--------------------------------------------------------------------------------------------------------------------------

Create webpack.config.js with the following contents

const path = require('path')
module.exports = {
   entry: path.join(__dirname, 'src/js', 'index.js'), // Our frontend will be inside the src folder
   output: {
      path: path.join(__dirname, 'dist'),
      filename: 'build.js' // The final file will be created in dist/build.js
   },
   module: {
      loaders: [{
         test: /\.css$/, // To load the css in react
         use: ['style-loader', 'css-loader'],
         include: /src/
      }, {
         test: /\.jsx?$/, // To load the js and jsx files
         loader: 'babel-loader',
         exclude: /node_modules/,
         query: {
            presets: ['es2015', 'react', 'stage-2']
         }
      }, {
         test: /\.json$/, // To load the json files
         loader: 'json-loader'
      }]
   }
}

//-------------------------------------------------------------------------------------------------------------------------- Create the following folder structure

    src/
        -- css/index.css
        -- js/index.js
    dist/
        -- index.html

//--------------------------------------------------------------------------------------------------------------------------

Create the file contracts/SmartSuiteContract.sol with the following contents

pragma solidity ^0.4.23;


contract SmartSuiteContract {
    address public owner;

    uint256 public minimumBid;

    uint256 public totalBid;

    uint256 public numberOfBids;

    uint256 public maxAmountOfBids = 100;

    address[] public users;

    struct User {
        uint256 amountBid;
        uint256 propertyNumberSelected;
    }

    // The address of the user and => the user info   
    mapping(address => User) public userInfo;

    function SmartSuiteContract(uint256 _minimumBid) public {
        owner = msg.sender;
        if (_minimumBid != 0 ) {
            minimumBid = _minimumBid;
        }
    }

    // Fallback function in case someone sends ether to the contract so it doesn't get 
    // lost and to increase the treasury of this contract that will be distributed in each game
    function() public payable {
    }

    function kill() public {
        if (msg.sender == owner) {
            selfdestruct(owner);
        }
    }

    function checkUserExists(address userAddress) public constant returns(bool){
        for (uint256 i = 0; i < users.length; i++) {
            if (users[i] == userAddress) { 
                return true;
            }
        }
        return false;
    }

    // To bet for a number between 1 and 10 both inclusive
    function bid(uint256 propertyNumberSelected) public payable {
        require(!checkUserExists(msg.sender));
        require(propertyNumberSelected >= 1 && propertyNumberSelected <= 10);
        require(msg.value >= minimumBid);
        userInfo[msg.sender].amountBid = msg.value;
        userInfo[msg.sender].propertyNumberSelected = propertyNumberSelected;
        numberOfBids++;
        users.push(msg.sender);
        totalBid += msg.value;
        if (numberOfBids >= maxAmountOfBids) {
            generateNumberWinner();
        }
    }

    // Generates a number between 1 and 10 that will be the winner
    function generateNumberWinner() public {
        uint256 numberGenerated = block.number % 10 + 1; // TODO : Improve security
        distributePrizes(numberGenerated);
    }

    // Sends the corresponding ether to each winner depending on the total bets
    function distributePrizes(uint256 numberWinner) public {
        address[100] memory winners; // We have to create a temporary in memory array with fixed size
        uint256 count = 0; // This is the count for the array of winners
        for (uint256 i = 0; i < users.length; i++) {
            address userAddress = users[i];
            if (userInfo[userAddress].propertyNumberSelected == numberWinner) {
                winners[count] = userAddress;
                count++;
            }
            delete userInfo[userAddress]; // Delete all the players
        }
        users.length = 0; // Delete all the players array
        uint256 winnerEtherAmount = totalBid / winners.length; // How much each winner gets
        for (uint256 j = 0; j < count; j++) {
            // Check that the address in this fixed array is not empty
            if (winners[j] != address(0)) {
                winners[j].transfer(winnerEtherAmount);
            }
            
        }
    }

}

//--------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------

Audit

==> npm audit

                   === npm audit security report ===                        

found 0 vulnerabilities in 6368 scanned packages

==> npm audit fix npm WARN babel-loader@8.0.2 requires a peer of @babel/core@^7.0.0 but none is installed. You must install peer dependencies yourself. npm WARN smartsuite-dapp@1.0.0 No description npm WARN smartsuite-dapp@1.0.0 No repository field.

up to date in 3.243s fixed 0 of 0 vulnerabilities in 6368 scanned packages

//--------------------------------------------------------------------------------------------------------------------------

Deployed on Ropsten : 0x8aadbc3a929c7234ea4ba9a16b14ab90e626a53e

Deployed on Ropsten : 0x775d2b664c3c6f41eaf979f07ad37ed21c923c8e

Tx Hash 0xd211189f2cb0938666f554fbbdbd6d6ad70f190c0461b8763269f8fd69d4277e

//--------------------------------------------------------------------------------------------------------------------------

Additional Info

https://medium.com/@guccimanepunk/how-to-deploy-a-truffle-contract-to-ropsten-e2fb817870c1 Generate a new Ropsten account

geth --testnet account new

Run the geth instance with permissions opened up like this

geth --testnet --fast --rpc --rpcapi eth,net,web3,personal

//------------------------------------------------------------------------------------------------------------------------------------

Steps

In the top-level smartsuite folder

==> create-react-app smartsuite

//------------------------------------------------------------------------------------------------------------------------------------

==> rails g controller Projects

//------------------------------------------------------------------------------------------------------------------------------------

==> rails s -p 3001

curl -G http://localhost:3001/api/v1/projects

//------------------------------------------------------------------------------------------------------------------------------------

==> npm install webpack -g

==> npm install -g webpack-cli

==> cd vitalix && npm install webpack --save-dev

//------------------------------------------------------------------------------------------------------------------------------------

==> npm install webpack-dev-server --save-dev //------------------------------------------------------------------------------------------------------------------------------------ https://thinkster.io/tutorials/build-a-real-world-react-redux-application

//------------------------------------------------------------------------------------------------------------------------------------

Dev

Inside that directory, you can run several commands:

yarn start Starts the development server.

yarn build Bundles the app into static files for production.

yarn test Starts the test runner.

yarn eject Removes this tool and copies build dependencies, configuration files and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

cd smartstack yarn start

//------------------------------------------------------------------------------------------------------------------------------------

Prod

==> yarn build

//------------------------------------------------------------------------------------------------------------------------------------

Steps

==> create-react-app smartstack

==> yarn add react-router

==> yarn add react-router-dom

==> yarn add semantic-ui-react semantic-ui-css

Add material-ui https://github.com/mui-org/material-ui

==> yarn add @material-ui/core

==> yarn add @material-ui/icons

==> yarn add prop-types

==> yarn add axios

==> yarn add react-redux

==> yarn add redux //------------------------------------------------------------------------------------------------------------------------------------

Update node to latest on mac

==> node -v v9.7.1

==> brew update

==> brew upgrade node

==> node -v v10.9.0

//------------------------------------------------------------------------------------------------------------------------------------

==> yarn add --dev eslint prettier eslint-config-airbnb@^15.0.1 eslint-config-prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-import eslint-plugin-jsx-a11y@^5.1.1

==> npm i eslint-plugin-prettier@latest --save-dev

yarn add eslint-loader --dev

==> npm install --save-dev eslint-config-prettier

==> npm install --save eslint-config-airbnb

//------------------------------------------------------------------------------------------------------------------------------------

==> firebase login Already logged in as rndfloinc@gmail.com ~/repos/rndflo/githubrepos/smartsuite/smartsuite-dapp-main (master) ==> firebase init

You're about to initialize a Firebase project in this directory:

/Users/das/repos/rndflo/githubrepos/smartsuite/smartsuite-dapp-main

? Which Firebase CLI features do you want to setup for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure and deploy Firebase Hosting sites

=== Project Setup

First, let's associate this project directory with a Firebase project. You can create multiple project aliases by running firebase use --add, but for now we'll just set up a default project.

? Select a default Firebase project for this directory: smartsuitedapp (smartsuitedapp)

=== Hosting Setup

Your public directory is the folder (relative to your project directory) that will contain Hosting assets to be uploaded with firebase deploy. If you have a build process for your assets, use your build's output directory.

? What do you want to use as your public directory? public ? Configure as a single-page app (rewrite all urls to /index.html)? Yes ? File public/index.html already exists. Overwrite? No i Skipping write of public/index.html

i Writing configuration info to firebase.json... i Writing project information to .firebaserc...

✔ Firebase initialization complete! //------------------------------------------------------------------------------------------------------------------------------------

Deploy

==> truffle deploy

==> truffle migrate --reset --network ropsten

==> truffle deploy --network ropsten

==> truffle migrate --reset --network ropsten Using network 'ropsten'.

Running migration: 1_initial_migration.js Replacing Migrations... ... 0x0937927545895077263d5cd2908eb4440d6531829f7623f89238ebd89614e57d Migrations: 0x883bb3dddedc347f712f4ac0d81c1027268f433c Saving successful migration to network... ... 0x6ab478107bc85496c2decbbe3b73edd9e8cac8d2d31427ae02e1bd6c5b942a47 Saving artifacts... Running migration: 2_deploy_contracts.js Deploying SmartSuiteContract... ... 0xca1a45e49ecf82951077d28fe2cc5280ab3f38b484685bd9532a4b1d992ef3b4 SmartSuiteContract: 0x4af5d1a821e8c5e026946578534418d9bd7b51f7 Saving successful migration to network... ... 0xcad6db69f49d3a45c9654ba5ffa249cf72b691f3985f4ab1aa4f88e656eaa463 Saving artifacts...

==> truffle console --network ropsten

SmartSuiteContract.deployed().then(function(instance){return instance });

contractAddress = 0x775d2b664c3c6f41eaf979f07ad37ed21c923c8e

web3.eth.contract(SmartSuiteContract.abi, contractAddress)

//------------------------------------------------------------------------------------------------------------------------------------

==> truffle console truffle(development)> const HDWalletProvider = require("truffle-hdwallet-provider"); undefined truffle(development)> const wallet = new HDWalletProvider('apple banana coffee', '') undefined truffle(development)> wallet

0x83ab80886a750131f1df0fd1bccee99992481782

//------------------------------------------------------------------------------------------------------------------------------------

Links

https://truffleframework.com/