Creating an Ethereum Token to Enable a Decentralized Rent-to-Own Network
By: Evan Diewald
Tags: Metamask, Defi, Smart Contracts, Ethereum, Rent To Own

Introduction

With real estate prices soaring to record heights, it has never been more difficult to qualify for a mortgage. Even those with steady, well-paying jobs can struggle to prove their creditworthiness and save up enough cash to start building equity in a home. Rent-to-Own, as the name implies, is an alternative route to homeownership in which renters have the option to purchase the property when their lease expires. While the terms of the agreement can vary, what this essentially means is that a certain portion of each rent check goes toward an eventual down payment. Ideally, this arrangement is a win-win: landlords benefit from extra-motivated tenants, and dependable renters are rewarded for their financial responsibility. However, in practice, Rent-to-Own is far from perfect. Renters who decide to move have to forfeit their accrued payments and start over. Predatory landlords change the terms at the last minute, and both parties must rely on each other to keep honest and accurate records.

Fortunately, innovations in Decentralized Finance (DeFi) offer a potential solution to these problems. Using smart contracts, we can program the business logic of rent-to-own agreements as independently-verifiable transactions in an immutable ledger. We can even create an cryptocurrency-based incentive system that rewards both renters and landlords. These are the principles behind the RTO token, the non-transferrable asset class that drives a potential network of Rent-to-Own participants. Let’s start with a conceptual overview of the (preliminary) economics before diving into technical details.

Motivation

For the RTO system to work, it must benefit all stakeholders. First, landlords who list a home through any rent-to-own scheme expect to make a certain amount of cash during the rental period before the sale. Typically, this represents some portion of the property’s appraisal value. Once this threshold is met, they want to sell to a motivated, creditworthy buyer. But how do you go about finding such a buyer? Credit scores do not tell the whole story, and references can be easily forged. Because of the difficulty in establishing trust through these imperfect metrics, landlords often have no choice but to allow each tenant to prove themselves through firsthand experience (i.e. years of on-time payments). For this reason, most rent-to-own agreements are non-transferrable, meaning that tenants have to return to square one if they decide to move.

Thus, a ubiquitous network of rent-to-own homes and participants would be advantageous. Property management companies would be one way to achieve this, but such centralized options remove individuals’ autonomy in exchange for standardization and shared infrastructure, like secure payment platforms and databases. RTO offers a decentralized alternative. We start by leveraging the secure, stable, and immutable financial transactions that are already baked into the Ethereum ecosystem, wrapping our business logic in a smart contract to establish trust among distributed network participants.

The RTO Smart Contract

Our smart contract is simple, but powerful. To list a rent-to-own home on the RTO network, landlords must first be verified by the contract administrator. Once approved, they can add their rental property, which is defined by the renter’s ETH address, an earnings threshold (representing a USD amount that they would like to recover before selling the home), and an earnings percentage (the fraction of each rental payment that will contribute toward the earnings threshold). New homes and renters are initialized with an empty RTO balance, and homes will not be sold until both buyer and seller have an RTO balance that exceeds the earnings threshold. This condition ensures that landlords are guaranteed a certain amount of profits and renters have proven themselves creditworthy.

Each time rent is paid (in ETH) through this smart contract, both the renter and home acquire non-transferrable, dollar-normalized RTO. The exact amount of RTO earned is determined by the following equation:

amountToMint = rentAmountEth * earningsPercent * usdPriceEth

So let’s say a home has a monthly rent of $2000 (market value of about 1 ETH at the time of writing), an earnings percentage of 20%, and an earnings threshold of $20,000. With each payment, 1 ETH * 20% * ($2000/ETH) = 400 RTO are added to the balances of both renter and home. At this rate, the renter will have the opportunity to purchase the house after about 4 years of steady payments. If they decide to move, both tenant and home retain their RTO balance. It’s important to note that valid rent payments are the only way to acquire RTO — tokens are non-transferrable, non-burnable, and cannot be swapped on secondary markets, as opposed to standard ERC20 coins. Like a credit score, there are no shortcuts to establishing good financial standing.

By making the critical information publicly available, the RTO network creates a competitive marketplace where, in addition to amenities and square footage, participants can compare and negotiate the terms of the earnings agreement. Even within the contract’s relatively simple boundaries, dozens of unique, mutually-beneficial scenarios can occur naturally, such as:

Renter and home both start with 0 RTO and renter does not move: This represents the traditional rent-to-own structure. Both entities reach the earnings threshold at the same time, at which point the renter can buy the house.

Renter RTO > Earnings Threshold & Home RTO < Earnings Threshold: Renter is ready but landlord is not. By the time both conditions are met, the renter may have enough leverage to negotiate for more a more favorable mortgage (e.g. 20 instead of 30-year term).

Home RTO > Earnings & Renter RTO < Earnings Threshold: The opposite of the last scenario. Here, the renter still has to prove themselves, but they may wish to accelerate their earnings by negotiating for a higher earnings percentage.

Code and Tutorial

Skip this section if you’d like to get right to the demo of the decentralized application.

Deploying the Smart Contract

The business logic discussed above is codified in the following smart contract, written in Solidity.

If you’re familiar with object-oriented programming languages, most of the code should be pretty straightforward. I would like to highlight a couple of key functions:

getThePrice() : RTO should be pegged to the dollar to account for the volatility in the price of ETH. To normalize ETH payments, we need a way to access the current USD/ETH market price. Unfortunately, we can’t just call the CoinGecko API within Solidity, but we can access a “Price Feed”, which cleverly stores the price on-chain via a Chainlink aggregator interface. More on that here.

: RTO should be pegged to the dollar to account for the volatility in the price of ETH. To normalize ETH payments, we need a way to access the current USD/ETH market price. Unfortunately, we can’t just call the CoinGecko API within Solidity, but we can access a “Price Feed”, which cleverly stores the price on-chain via a Chainlink aggregator interface. More on that here. payRent(address _to): This is the heart of the smart contract, so it deserves special consideration. First of all, we make sure that the payment is made from the home’s renter to its verified landlord. Next, as a payable function, we also facilitate the transfer of ETH (L119), the amount of which is stored in the transaction data. Finally, we calculate amountToMint (see the equation above) and update the balances of home and renter accordingly.

I deployed the smart contract to the Ropsten Testnet using the Remix IDE and my Metamask wallet. Here are more detailed instructions if you’re interested. Before we move on to the application, we (as the contract deployer) need to add a verified landlord and sign the transaction using the same account that deployed the contract (representing a trusted administrator). We can do that right in Remix.

Image by author.

We can also view our contract and all associated transactions on Etherscan.

Application Infrastructure and Metamask Integration

The application provides methods for us to use the smart contract functions through a payment portal-esque interface. I’m using Python’s FastAPI to create the API endpoints, the Web3.py library to prepare (but not sign, more on that in a second) the Ethereum transactions, and a basic PostgreSQL database to store some off-chain data, like URL’s to images of the homes. Rather than asking the user to hard-code their private keys into the application itself (a SERIOUS security risk), we sign transactions using the popular Metamask browser extension. For example, we generate the transaction data for the payRent function like this:

# from transactions.py def payRent(landlord, amount_eth):

txn_dict = to_contract.functions.payRent(w3.toChecksumAddress(landlord)).buildTransaction({

'chainId': 3,

'value': w3.toWei(float(amount_eth), 'ether'),

'gas': 2000000,

'gasPrice': w3.toWei('2', 'gwei')

})

return txn_dict

We can then send this data to Metamask with a few lines of JavaScript:

# from confirm_transaction.html sendTxnButton.addEventListener('click', () => {

sendTxnButton.disabled = true;

sendTxnButton.innerHTML = "Connecting to Metamask...";

ethereum

.request({

method: 'eth_sendTransaction',

params: [

{

from: ethereum.selectedAddress,

to: "{{contract_address}}",

value: "{{value}}",

gasPrice: '0x4A817C800',

gas: '0x1E8480',

data: "{{txn_data}}",

chainId: '0x3'

},

],

})

.then((txHash) => logTransaction(txHash))

.catch((error) => console.error);

});

The full project code, with instructions of how to run the demo application, can be accessed here.

Demo

Now for a quick demo that demonstrates functionality from the perspectives of both landlord and renter. Before the tenant and home can start earning RTO, our landlord will have to add their property to the smart contract. They can do that by navigating to the “View Listings” tab and filling out a quick form.

Role: Landlord

Listing a new rental on the RTO network. Image by author.

Some of these values, like the street address and description, will be stored in our off-chain database. Others, like the down payment (aka earnings threshold) and earnings percentage, will be stored in the smart contract. This page simply prepares the function details, but they will then be asked to explicitly sign the transaction using their Metamask wallet.