Alberto Cuesta Cañada

Hello. I design and build blockchain solutions. I like to make the complex simple.

How to Tokenize Houses on a Blockchain

Including a code sample using the ERC20 token standard.

Introduction

I have ways of making money that you know nothing of.  - John D. Rockefeller
One common use case that keeps popping up in my blockchain development projects is tokenization of digital assets. Cryptocurrencies are already a few years old and their capabilities are starting to be understood. Now business leaders are looking to other assets that could be traded using the same technologies.
The attraction of such use cases is clear. Obtaining a tiny fraction of all trades in a large market is an immensely profitable business. Many markets today are inefficient and are juicy targets for disruption.
One easy example are real estate markets because the assets traded are all unique and non-fungible. The house I sell is different from the house you sell, and in regular conditions I can’t sell only half of my house. This is different from a currency market where I can sell you any amount of my Euros for your Dollars, and no one cares which specific banknotes they receive.
Implementing a real estate market in the blockchain sounds like good business. It is a very inefficient market with a truly enormous trading volume. If you implement an alternative that charges a fraction of the fees and removes some of the inconvenience you will become very rich even if the fees that you charge are minuscule.
If you have some knowledge of the blockchain universe you might think that I’m going to explain now how to tokenize houses into ERC721 tokens. It looks like a perfect fit. A house is a non-fungible unique item and so it an ERC721 token.
If you implement a functioning real estate market on the blockchain you will become very rich.
That would be a perfect case and implementation for a land registry. A simple digital representation of the physical world. If you work for a government body and want some help on implementing that I’ll be happy to help. However, business plans trying to profit with a tokenization scheme need to go beyond simple representation and to offer something new.
In this article I’m going to show an example of tokenizing real estate that makes houses a commodity and redistributes revenue. I’m going to use an ERC20 standard, generate shares on a real estate portfolio and distribute dividends to the stakeholders.

Real Estate through ERC20

Tokenizing real estate is akin to creating a REIT. A company acquires real estate and then sells it as fractional shares in an exchange. The shares change in price with the underlying assets and rents are distributed as dividends, after subtracting an amount for the company that holds and manages the assets.
We can implement this on a blockchain with an ERC20 contract that represents a group of real estate assets. The tokens generated by the contract would be fractional shares that can be traded in some market. With this anyone can create their own REIT from their properties and find investors from around the world.
The ERC20 contract linked to the property processes the revenue flows associated with the property. Debtors and investors automatically receive the revenue due to them.
Tokenizing real estate is akin to creating a REIT.
Token holders can also trade their shares by using the standard ERC20 methods. If this is subject to restrictions we would extend the contract with a standard such as ERC1404.

Implementation

This smart contract is longer than what I usually publish for an article. Most of the complexity results from recording who are the token holders, which is not included in the standard ERC20 implementation.
If you want to fork this code for your own purposes you are welcome to do so.
This contract:
  • Implements ERC20.
  • Represents a Real Estate Portfolio, and each token is a share in it.
  • Records the stakeholders that can hold tokens.
  • Allows receiving Ether.
  • Allows distributing Ether to stakeholders proportionally to the tokens they own.
  • Holds Ether for stakeholders until they are ready to withdraw it.
    pragma solidity ^0.5.0;
    
    import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
    import "openzeppelin-solidity/contracts/math/SafeMath.sol";
    import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
    
    
    /**
    * @title Real Estate Token
    * @author Alberto Cuesta Canada
    * @notice Implements a real estate tokenization contract with 
    * revenue distribution.
    */
    contract RealEstateToken is ERC20, Ownable {
       using SafeMath for uint256;
    
       /**
        * @notice We require to know who are all the stakeholders.
        */
       address[] internal stakeholders;
    
       /**
        * @notice The accumulated revenue for each stakeholder.
        */
       mapping(address => uint256) internal revenues;
    
       /**
        * @notice The funds in this contract that haven't been 
        * distributed yet.
        */
       uint256 internal accumulated;
    
       /**
        * @notice The constructor for the Real Estate Token. This 
        * contract relates to a unique real estate portfolio and each
        * token minted is a share.
        * @param _owner The address to receive all tokens on 
        * construction.
        * @param _supply The amount of tokens to mint on construction.
        */
       constructor(address _owner, uint256 _supply)
           public
       {
           _mint(_owner, _supply);
       }
    
       /**
        * @notice Method to send Ether to this contract.
        */
       function ()
           external
           payable
       {
           accumulated += msg.value;
       }
    
       /**
        * @notice Transfers are only allowed to known stakeholders.
        * @param _recipient The address to receive the tokens.
        * @param _amount The amount of RealEstateTokens to send.
        */
       function transfer(address _recipient, uint256 _amount)
           public
           returns (bool)
       {
           (bool isStakeholder, ) = isStakeholder(_recipient);
           require(isStakeholder);
           _transfer(msg.sender, _recipient, _amount);
           return true;
       }
    
       // ---------- STAKEHOLDERS ----------
    
       /**
        * @notice A method to check if an address is a stakeholder.
        * @param _address The address to verify.
        * @return bool, uint256 Whether the address is a stakeholder,
        * and if so its position in the stakeholders array.
        */
       function isStakeholder(address _address)
           public
           view
           returns(bool, uint256)
       {
           for (uint256 s = 0; s < stakeholders.length; s += 1){
               if (_address == stakeholders[s]) return (true, s);
           }
           return (false, 0);
       }
    
       /**
        * @notice A method to add a stakeholder.
        * @param _stakeholder The stakeholder to add.
        */
       function addStakeholder(address _stakeholder)
           public
           onlyOwner
       {
           (bool _isStakeholder, ) = isStakeholder(_stakeholder);
           if (!_isStakeholder) stakeholders.push(_stakeholder);
       }
    
       /**
        * @notice A method to remove a stakeholder.
        * @param _stakeholder The stakeholder to remove.
        */
       function removeStakeholder(address _stakeholder)
           public
           onlyOwner
       {
           (bool _isStakeholder, uint256 s) 
               = isStakeholder(_stakeholder);
           if (_isStakeholder){
               stakeholders[s] 
                   = stakeholders[stakeholders.length - 1];
               stakeholders.pop();
           }
       }
    
       /**
        * @notice A simple method that calculates the proportional 
        * share for each stakeholder.
        * @param _stakeholder The stakeholder to calculate share for.
        */
       function getShare(address _stakeholder)
           public
           view
           returns(uint256)
       {
           return balanceOf(_stakeholder) / totalSupply();
       }
    
       // ---------- REVENUE ----------
       /**
        * @notice A method to distribute revenues to all stakeholders.
        */
       function distribute()
           public
           onlyOwner
       {
           for (uint256 s = 0; s < stakeholders.length; s += 1){
               address stakeholder = stakeholders[s];
               uint256 revenue 
                   = address(this).balance * getShare(stakeholder);
               accumulated = accumulated.sub(revenue);
               revenues[stakeholder] 
                   = revenues[stakeholder].add(revenue);
           }
       }
    
       /**
        * @notice A method to withdraw revenues.
        */
       function withdraw()
           public
       {
           uint256 revenue = revenues[msg.sender];
           revenues[msg.sender] = 0;
           address(msg.sender).transfer(revenue);
       }
    }

Drawbacks

Just because we can do something it doesn’t mean that we should.
As many others I have some of my savings in the stock market. I don’t know that much about investing so I buy broad ETFs and sometimes REITs. Owning shares in a huge fund reduces my risk of the fund going bankrupt for some reason beyond my control or understanding. I would imagine that owning a bit of a $10B fund managed by someone like BlackRock is safer than owning a larger share of a $1M fund managed by some unknowns.
I see the same issues with tokenizing real estate. I would worry about having a significant share of my savings in an asset that I can’t control. I wonder if my tokens will give me any legal ownership of the asset and which legal protections will I have. Maybe none.
Just because we can do something it doesn’t mean that we should.
Blockchain is best when it is decentralized and removes intermediaries. If I seek protection by buying tokens from a huge company I am introducing the intermediary. Blockchain in this scenario doesn’t seem better than the current system of brokers and REITs.

Conclusion

Tokenization is a poorly understood concept and is usually described as representing physical assets with an ERC721 token. While that is a good case for an asset registry it is not that exciting as a business model.
In this article I described a different tokenization implementation using the ERC20 standard. This implementation overcomes trading limitations and introduces new financial vehicles in a real estate context.
My job is to show business leaders how things work and what they can do with technology. I’m usually not the one with the brilliant business ideas and the deep business knowledge.
Now it is up to the business leaders to run with this knowledge and come up with a good use for these new tools that remove intermediaries, decentralize trade, and generate value.

Tags

More by Alberto Cuesta Cañada