Leon Di, Product Marketing @ WeTrust

This is the first of a four part series describing in detail how the WeTrust distributed App (dApp) works!

WeTrust is a collaborative insurance and savings platform on the blockchain. It was created to enable groups of people to create their own savings and insurance blockchain organizations on the blockchain. These organizations, known as Trusted Lending Circles and as Rotating Savings and Credit Associations (ROSCAs), have been used in many parts of the world, providing financial services to people who do not have access to traditional financial institutions. But how does the WeTrust platform actually make this Trusted Lending Circle “magic” happen? The WeTrust Trusted Lending Circle dApp is composed of the smart contracts which implement the rules of a Trusted Lending Circle, an optional WeTrust frontend that simplifies the creation of and participation in Trusted Lending Circle contracts, and a WeTrust backend that makes checking the status of a Trusted Lending Circle more efficient. Let’s explore the different parts in more detail.

The WeTrust Trusted Lending Circle Smart Contract

The most important part of the WeTrust dApp is the smart contract which implements the rules of a Trusted Lending Circle. The contract is written in Solidity, an object oriented programming language developed specifically for writing contracts on the Ethereum network. When contracts are deployed to the Ethereum blockchain, they are given a unique address, which consists of a bunch of hexadecimal characters. Within each contract, function declarations implement the defining rules of the smart contract. Solidity also provides language constructs specifically targeted at logging on the blockchain, such as the event primitive and the indexed keyword. A Solidity program is eventually compiled into bytecode, to be run on the Ethereum Virtual Machine (EVM).

Each WeTrust Trusted Lending Circle group will have its own smart contract on the Ethereum blockchain, with a unique identifying address. This address will allow WeTrust users to distinguish their contract from the others present on the WeTrust network. In addition to an address, the contract will hold other information important to the Trusted Lending Circle, such as:

Addresses of Participants in the Trusted Lending Circle: Everyone who participates in a Trusted Lending Circle does so from their own Ethereum account. The address of this account is stored in the smart contract, and participation interactions can only occur from these addresses. WeTrust has no hosted accounts, so the participant will use their Ethereum address to interact directly with the smart contract. This reduces the friction between owning Ether and participating in a Trusted Lending Circle, and also alleviates safety concerns.

Contribution Size: The amount each Trusted Lending Circle participant should contribute to the pool of funds during each round. Contribution Size is specified in units of Wei (1e-18 Ether). WeTrust has plans to enable usage of additional tokens and stablecoins.

Round Period: The number of days each round of the Trusted Lending Circle will last for. Round Period is specified in Days.

Start Time: This specifies the date on which the Trusted Lending Circle starts. Since Solidity doesn’t accept a date format, what is stored on the smart contract is actually specified in terms of Unix time, though the user front-end can recognize traditional calendar dates.

Fee: Fee specifies the amount which WeTrust will will receive during each round of the Trusted Lending Circle. The fee is specified in thousandths of a percent (i.e. multiples of 0.001%), and is generally a value between 0.0% and 0.3%. WeTrust may explore alternative platform attracts more and more users, this fee will be reduced.

Below, we see a sample Trusted Lending Circle smart contract, with each of these fields specified. In this example contract, the Round Period is set to 1 week, the Contribution Size is 2 Ether per one week round, the Start Time is set as July 4th in the year 2017, the Participants are members of WeTrust’s founding team and software development team (with fake WeTrust addresses being shown, of course), and the Fee is set as 3 thousandths, or (3*0.001)=0.3%.

The WeTrust Front-End

WeTrust users have 2 different ways of accessing the dApp and interacting with the smart contract: the WeTrust front-end provides a convenient GUI interface for accessing the dApp, and it is also possible for users to access the smart contract API directly using function calls. When calling the smart contract directly, the user has multiple API functions at their disposal for accomplishing tasks such as contributing to a Trusted Lending Circle round or reading the balance of funds currently in the Trusted Lending Circle. These API functions are accessed via web3.js, a JavaScript library developed to allow easier interfacing with the Ethereum blockchain.

Interacting with the smart contract directly though the contract’s API requires the user to have their private key and the full address of their Trusted Lending Circle’s smart contract handy, as well as in-depth knowledge of the Ethereum blockchain APIs. For WeTrust users who don’t want to deal with these intricacies, there is an easy to use WeTrust GUI that makes calling the API functions listed above as simple as clicking on a button.

To use the WeTrust frontend, participants need a Web3 compatible browser. There are a couple of good ways to do this, we recommend either using the MetaMask browser extension, or Mist. Both require users to sign each transaction manually.

The WeTrust Backend

Often times, a WeTrust user only wishes check on the Trusted Lending Circle. At other times, the user may wish to be notified when the smart contract changes in some way — for example, when a new user the foreperson invites joins the Trusted Lending Circle or when a new lowest bid occurs. To enable the user to do this, WeTrust maintains a backend server that mirrors the state of the current Trusted Lending Circles by constantly monitoring the ethereum blockchain for contract events. Checking the status of the Trusted Lending Circle through the website is much faster and more intuitive than interacting with the smart contract directly. In addition, the backend simplifies the process of deploying a new Trusted Lending Circle, allowing the user to invite other users via email instead of having to manually collect their ethereum addresses.

Note that users who deploy the Trusted Lending Circle contract directly via the API will not be able to access the backend, and must always go through the Ethereum blockchain instead. The full flow of transactions on the WeTrust network from the user to the smart contract is shown below.

Follow the WeTrust blog and tune in next week for Part 2 of How WeTrust Works Under the Hood, where we dive in to the details of how the frontend implements the API and interacts with the backend!

And to chat with us directly and be the first to know what we’re up to, join our Slack Channel!