Skip to content

josephpasik/theblock-web3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GO BROKERLESS!

Free of Concern "Libre de preocupación"


Overview

In this project, we are helping you break free from broker hassles. Our distributed ledger is built upon ethereum programming in Solidity. Let's walk through this exciting process together!

Engaging Parties

Party Address Interpretation
Landlord landlord crypto wallet of the landloard
Tenant tenant wallet address of the candidate tenant
Previous Tenant previous wallet address of the previous tenant leaving
Us us our crypto wallet address

Escrow Account

Account Address Interpretation
Omnibus _omnibusAddress contract address of all deposits to earn interests from the bank

Variables

Variable Code Explanation
Rent rent monthly rent for bidding
Deposit deposit deposit from the higher bidder, equivalent to one-month rent
showingfeepercent showingfeepercent percent of rent for showing the property to candidate tenants
servicefeepercent servicefeepercent as a percent of monthly rent
Apartment apt a string combination of zip code, building number, and apt number

Entity Relationship Diagram

erd


Blockchain Technologies

  • Target Ethereum Virtual Machine (EVM), influenced by
  • Extension installed in Visual Studio Code: Link to Github

See also: Web3 on Github

  • API in JavaScript for Ethereum

    • libaries use HPPT or IPC to connect to nodes
  • Use web3.eth package to interact with smart contract on Ethereum blockchain

    • See ledger.py

      Python code
      def reportApt(landlord, report_uri):
        tx_hash = registerApt.functions.reportApt(landlord, report_uri).transact(
            {"from": w3.eth.accounts[0]}
        )
        receipt = w3.eth.waitForTransactionReceipt(tx_hash)
        return receipt
      Code in Python
      def initContract():
          with open(Path("brokerless.json")) as json_file:
              abi = json.load(json_file)
      
          return w3.eth.contract(address=os.getenv("REGISTERAPT_ADDRESS"), abi=abi)
  • Report apartments through python: see py_dApp

    • ABI acquired from compiling Solidity smart contracts in Remix

    • Environmennt setup

      Need Pinata API and secret API keys in a file .env to access URIs
      PINATA_API_KEY=
      PINATA_SECRET_API_KEY=
      WEB3_PROVIDER_URI=http://127.0.0.1:8545
      REGISTERAPT_ADDRESS=0x
      
    • Next step: for landlord

      • Report and getting report on bidders
      • following similar process
  • Personal blockchain DApp for Ethereum development
  • Linked with MetaMask to Localhost:8545 in this project demo
  • Desktop application installed

Contracts

Defined in Brokerless.sol:

  • Auction
Solidity code for capital distribution
      // in Constructor
        servicefeepercent = 5;
        showingfeepercent = 25;

      // within function auctionEnd() public
      // 3. Interaction
        rent = highestBid * rentPercent/100;
        deposit = highestBid * depositPercent/100;

      //leaseAddress.transfer(rent);
        omnibusAddress.transfer(deposit);
        previous.transfer(rent * showingfeepercent/100); // to previous contract to pay showingfee
        landlord.transfer(rent - (rent * showingfeepercent/100) - (rent * servicefeepercent/100));
        us.transfer(rent * servicefeepercent/100);
  • Lease
Solidity code for deposit return
    function returnDeposit() external 
    onlyLandlord
    {
        Omnibus omnibus = Omnibus(omnibusAddress);
        omnibus.releaseDeposit(tenant, landlord, deposit);
    }
  • Omnibus
Solidity code for computing fund allocation
      // in Constructor
        interestRate = 1;
        enhancedSpread = 3;
        tenantInterestSplit = 60;
        landlordInterestSplit = 20;
        usInterestSplit = 20;

      // under function releaseDeposit
        tenantInterestPayment =  (deposit * interestRate/100) + (deposit * enhancedSpread/100 * tenantInterestSplit/100);
        landlordInterestPayment = (deposit * enhancedSpread/100 * landlordInterestSplit/100);
        usInterestPayment = (deposit * enhancedSpread/100 * usInterestSplit/100);

        tenant.transfer(deposit);
        tenant.transfer(tenantInterestPayment);
        landlord.transfer(landlordInterestPayment);
        us.transfer(usInterestPayment);
  • BankInterest
Solidity code to generate funds in Omnibus bank account
    function generateFunds() public payable {
        
        Omnibus.transfer(msg.value);
    }

Defined under BankInterestGenerator.sol

  • BankInterest

NOTE: Funding through BankInterest contract in Omnibus account may be substituted by transfering funds in MetaMask under Localhost: 8545.

Addresses and Variables

List of Variables and Addresses engaged in contracts
Contract Variables Addresses
Lease apt, rent, deposit, shwoingfeepercent, servicefeepercent landlord, tenant, us, consolidatedDeposits, previous, omnibusAddress
Omnibus interestRate,enhancedSpread,tenantInterestSplit,landlordInterestSplit,usInterestSplit,tenantInterestPayment,landlordInterestPayment,usInterestPayment landlord, tenant, us
Auction apt,highestBid,rentPercent,depositPercent,rent,deposit,servicefeepercent,showingfeepercent us, landlord, leaseAddress, omnibusAddress, previous, tenant
BankInterest Omnibus Omnibus = _omnibusAddress

State (snapshots in process)

State variable for emitted events
Contract Variable Value
Auction state Started, Terminated
Lease state Created, Started, Terminated

Mapping

Map a variable onto positive integers
Contract Variable Value Rationale
Auction pendingReturns uint: positive integer withdrawals of overbids

Constructors

Construct contracts by assigning values to variables
Contract Variable Sample Code
Auction omnibusAddress,leaseAddress,landlord, apt,previous,us,servicefeepercent,showingfeepercent servicefeepercent = 5;
Lease us us = msg.sender;
Omnibus interestRate,enhancedSpread,tenantInterestSplit,landlordInterestSplit,usInterestSplit,us usInterestSplit = 20; us = msg.sender;

Modifiers

Modify conditions
Contract Modifier Code
Auction inState require(state == _state);
Auction onlyLandlord require(landlord == msg.sender);
Lease onlyLandlord require(landlord == msg.sender);
Lease onlyTenant require(tenant == msg.sender);
Lease onlyUs require(us == msg.sender);
Lease inState require(state == _state);

Events

Events for dApps to listen to
Contract Event Code
Auction rentIncreased event rentIncreased(address bidder, uint amount);
Auction AuctionEnded event AuctionEnded(address winner, uint amount);
Lease landlordConfirmed require(landlord == msg.sender);
Lease tenantConfirmed require(tenant == msg.sender);
Lease paidRent require(us == msg.sender);
Lease paidDeposit require(state == _state);
Lease returnDeposit require(state == _state);
Lease paidShowingFee require(state == _state);
Lease contractTerminated require(state == _state);

Functions

Nested inside contracts for various purposes
Contract Function Purpose
Auction bid allow rent increases based on highest bid after auction starts based on State
Auction withdraw withdraw an overbid
Auction pendingReturn amount for withdraw function
Auction getbalance return balance of the address
Auction auctionEnd landlord end the auction: rent, deposit, fees transfered to landlord, omnibus, previous tenant and us
Lease contruct assign variables event-based values: _landlord, _omnibusAddress, _rent, _deposit, _apt)
Lease payRent allow tenant to pay rent to landloard after contract starts as indicated by State
Lease returnDeposit enable landlord to reutrn depost to the leaving tenant from omnibus account upon contract termination
Lease requestShowingFee pay showing fee to the previous tenant
Lease terminateContract landlord concludes the lease contract
Lease getbalance return balance of the contract
Lease () payable external required for the lease contract to be payable from an outside account
Omnibus releaseDeposit transfer interests and principal on deposit to tenant, landlord and us based on specified schedules
Omnibus getbalance return balance of the contract
Omnibus () payable external required for the lease contract to be payable from an outside account
BankInterest generateFunds() transfer funds to _omnibusAddress

Workflow

Standing on shoulders of giants

LEASEHOLD: token distribution of smart contracts on rental lease

leasehold_token Source: Leasehold Token - The Decentralized Money Making Through Sort Term Rental Tokenization

Step-by-step Guide

Accounts

  • Tune in MetaMask to Localhost 8545.
  • Balances of accounts are viewable in Ganache.

Ganache Balances Prior to Transactions

Five accounts with the following wallet addresses engage in transactions on BrokerlessMarket (first five in Ganache):
Us: 
0x0616d31438078849D3bf66591855B3D3239a9E5c

Landlord: 
0x5DBaBe19DD1fedba1B20047059DCd755D8221BF7

Tenant: 
0x3e9D41Ec700b98C773f2599052a3590931bEa98c

Previous: 
0x8EaaBB9Fc753df2C50F0b01E99b4e0F1f2d970A6

Bank: 
0xBb2e65E2d7664E51A1547767d502169591642491

Demo Transactions

Initiate Lease Contract

In Remix, open Brokerless Contract

  • As Us in MetaMask:
    • Scroll and choose Lease under CONTRACT

    • Complile Lease Contract

    • Select Injected Web3 as ENVIRONMENT and deploy Lease Contract

      Lease Contract Deployment

      us_deploy_lease_0

    • After clicking the Deploy button, confirm on MetaMask for New Contract initiation

      • (Optional) Copy the address of the deployed Lease Contract by clicking on the page button to the right onto a .txt file: 0x0717c8C6c171E16dFE06d4df366d6fff017be521
      Notification of New Contract on MetaMask

      us_deploy_lease_1

      Confirmation of Deployment on MetaMask

      us_deploy_lease_2

    • Check our balance on Ganache

      Ganache Balance for Us dropped 0.02 ETH from 134.40 ETH to 134.38 ETH following Deployment of Lease Contract

      Ganache Balances following Lease Contract Deployment


Initiate Omnibus Contract

  • As Us in MetaMask:

    • Scroll down under CONTRACT and choose Omnibus

    • Compile the Omnibus Contract

    • Deploy Omnibus Contract under the same Injected Web3 ENVIRONMENT

      • (Optional) Copy the address of the deployed Omnibus Contract by clicking on the page button to the right onto a .txt file: 0x721080d169713ec439db4CaE8ED2daCEF4745B5d
      Omnibus Contract Deployment

      us_deploy_omnibus_0

    • Check our new balance on Ganache

      Ganache Balance for Us dropped 0.01 ETH from 134.38 ETH to 134.37 ETH following Deployment of Omnibus Contract

      Ganache Balances following Omnibus Contract Deployment


Initiate Auction Contract

  • As Us in MetaMask:

    • Scroll down under CONTRACT and choose Auction

    • Compile and Deploy Auction Contract, leaving Injected Web3 ENVIRONMENT unchanged

      • (Optional) Copy the address of the deployed Auction Contract by clicking on the page button to the right onto a .txt file: 0xf3B554248FDFFc24CE7Aa14689Ed561e0350B801
      Auction Contract Deployment

      us_deploy_auction_0

      MetaMask Notification on Auction Contract Deployment

      us_deploy_auction_1

    • Check our new balance on Ganache

      Ganache Balance for Us dropped 0.03 ETH from 134.37 ETH to 134.34 ETH following Deployment of Auction Contract

      Ganache Balances following Auction Contract Deployment


Bid as Tenant

  • As Tenant in MetaMask, i.e. the third address from the top in Ganache:

  • To initiate a bid, enter 10 ether as VALUE under CONTRACT Auction

    • Enter wallet addresses of landord, previous tenant with lease and omnibus contract addresses under DEPLOY section (may be left unchanged from Auction deployment)

    • Scroll down to unfold AUCTION under Deployed Contracts, enter 50 for _rentPercent and _depositPercent respectively for bid

      Tenant Bid 10 ETH with 50-50 Split on Rent and Deposit

      tenant_bid_auction_10eth

    • Compare balances on Ganache Pre and Post Tenant Bid

      Ganache Balance prior to Tenant's bid of 10 ether

      Ganache Balances prior to Bid

      Balances on Ganache following Tenant's bid of 10 ether: a drop from 67.13 ETH to 57.13 ETH posted on the third wallet, i.e. the candidate tenant's account

      Ganache Balances post Tenant Bid

    • The auction would only proceed should there be a higher bid than 10 ether from this point

      A bid of 14 ether that is greater than the previous bid of 10 ether

      tenant_bid_auction_14eth

      Balances on Ganache following Tenant's bid of 14 ether: a drop from 57.13 ETH to 43.12 ETH posted on the third wallet, i.e. the candidate tenant's account. An extra 0.01 ETH gas fee incurred for the bidding.

      Ganache Balances post 14 ETH Tenant Bid

      Get Balance by pressing **getbalance** button under the Deployed Omnibus Contract: current balance is 50% of 14 ETH, i.e. 7 ETH = 7 * (10^18) Wei

      Ganache Balances post 14 ETH Tenant Bid

      Should there be another bid in the valud of 14 ETH. An error message would pop up as follows:

      tenant_bid_auction_14eth_2


Depost to Generate Interest on Omnibus Bank Account

  • As Us in MetaMask, i.e. the second address from the top in Ganache:

    • Open BankInterestGenerator in Solidity

      • Expand view on Deployed Auction Contract at the bottom left-hand-side
    • Complile and Deploy BankInterest contract

      • at the previously deployed address of the Omnibus Contract under Brokerless Solidity_OMNIBUSADDRESS: 0x721080d169713ec439db4CaE8ED2daCEF4745B5d

      us_deploy_BankInterest_0

    • Confirm CONTRACT DEPLOYMENT on the MetaMask pop up notification window by clicking on Confirm button

      Confirm Deployment of BankInterest Contract

      us_deploy_BankInterest_1


Get Funds from Omnibus Bank Account

  • As Bank in MetaMask, i.e. the fifth address from the top in Ganache:

    • Enter 50 ether as VALUE on the Remix Deployment page

      • Keep BankInterest under CONTRACT selection
      • Keep _OMNIBUSADDRESS the same as the address of the previously deployed Omnibus Contract from Brokerless Solidity: 0x721080d169713ec439db4CaE8ED2daCEF4745B5d
    • Expaned view of the deployed BankInterest Contract and click on generateFunds button

      bank_transfer_50eth

    • Confirm CONTRACT INTERACTION on the MetaMask notification by clicking on Confirm button

      Omnibus Bank Account balance dropped from 100 ETH to 49.9994 ETH. The difference is resulted from gas fee.

      bank_transfer_50eth_1

      Balances on Ganache before and after the balance transfer of 50 ether are show below:

      Ganache Balances Prior to 50 ETH Transfer

      Ganache Balances After 50 ETH Transfer


Return Deposit

  • As Landlord in MetaMask, i.e. the second address from the top in Ganache:

    • Expand view of the deployed Lease Contract

    • Click on returnDeposit button

    • Confirm on the MetaMask via Confirm button

      landlord_returndeposit_0

      The balance of Tenant's account went up 7 ETH from 43 ETH to 50 ETH approximately.

      landlord_returndeposit_ganache_post


Conclude Auction

  • As Landlord in MetaMask, i.e. the second address from the top in Ganache:

  • To conclude an auction, under Auction Contract on Deployment page

    • Expand view on Deployed Auction Contract at the bottom left-hand-side

    • Press auctionEnd button

    • Confirm AUCTION END on the MetaMask pop up notification window by clicking on Confirm button

      Terminate Auction by Landlord

      landlord_auctionend_0

      landlord_auctionend_1

      Balances on Ganache following Tenant's bid of 10 ether: a drop from 67.13 ETH to 57.13 ETH posted on the third wallet, i.e. the candidate tenant's account

      Ganache Balances post Tenant Bid

Archived Process for Previous Versions
--------------------------------------
********CONTRACT DEPLOYMENT***********
--------------------------------------
* As Landlord deploys Auction contract 
* As Us deploy Lease contract
* As Us deploy the Omnibus contract
--------------------------------------
** Insert bank interest 5%
--------------------------------------


--------------------------------------
*********LEASE CONTRACT**************
--------------------------------------
* Set leaseAddress contract
* Set omnibusAddress contract
* As potentialTenant 1 enter bid Value and split Value between 
  rent percent and deposit percent
* As potentialTenant 2 enter higher bid Value and split Value
  between rent percent and deposit percent
* As potentialTenant 1 withdraw bid to get back money
* As Landlord end auction and accept highest bid. Resulting in the rent being transferred
  to lease contract and deposit gets transferred to the Omnibus contract
--------------------------------------
** Navigate to the Lease contract. As Landlord confirm lease contract
** As Tenant confirm lease contract
--------------------------------------


--------------------------------------
**********OMNIBUS CONTRACT***********
--------------------------------------

* Set Omnibus contract
* Set Previous contract
* Click initialPayout
* Rent payment is transferred to Landlord and Previous Tenant for showing
 the house and Us for offering the platform
--------------------------------------
** In the Previous Tenant Agreement set 
** Click PayRent 
** After duration press requestDeposit
--------------------------------------


Results

Wix Frontend + Backend View

Hakuna matata! This is how it appears!

Hakuna matata

Frontend: Set up a Webpage on Github

Step 1: Click on `Settings` on the Github repository

webpage_settings

Step 2: On Github Pages, select `master branch ` as `Source` and select a theme under `Theme Chooser`

webpage_githubpages

Step 3: Open the link to the webpage published highlighted in green to view this page

webpage_link

Step 4: Click on the link `here` under Demo App from the previous step to bid on BrokerlessMarket

webpage_raw

Step 5: Register an apartment by entering Apartment name, Pinata API and Secret API Key

webpage


Next Steps

We would like to elaborate on the following aspects on our project:

  • Duration of contract
  • Auction contract should create brokerless contract.
    • Or contract factory for may empty lease contracts to exist in waiting.
  • Vetting with machine learning
    • Invest deposit with machine learning
  • Add damage report
    • for landlord, require picture submission, allow withdrawal of deposit funds
    • for bidders, from perspectives of a landlord
  • Rather than auction process:
    • bidders should offer rent and deposit fee
    • Landlord should be able to choose which to accept
    • Landlord to set minimum
  • Add “paper” contract as URI
    • json
    • pdf
    • png
  • Allow tenants to offer a higher security deposit that the landlord is allowed to invest (전세) -> more security for the landlord (better tenants)
  • Link with property listing platform
  • Late fee (require payRent function even month)
  • Events in place for javascript Dapps to listen to
    • For user friendly UI
  • Hosting a factory of contracts for multiple apartments: Example on Github

Files


Solidity


Frontend dApps

BrokerlessMarket Frontend Webpage

dApps for Property Records


Supplementary

Google Drive and Slack Resources

Images


References

About

Solidity contracts that provide backend functionality for a web platform where tenants and landlords interact on a peer-to-peer network

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •