Getting started with Getline.ts

Olaf Tomalka
Getline.in
Published in
6 min readNov 22, 2017

The Getline Network and decentralized lending is a huge undertaking that we aim to improve over the next few years. Our first step to the huge vision written down in our whitepaper was to release a Typescript library called getline.ts. With it you can create your own applications interfacing directly with the decentralized Getline Network, without fighting with all the details such as managing web3.js, versioning smart contracts, hard coding ABIs, etc.

With the first iteration of the library you can now easily:

  • Access the latest Smart Contract version and it’s ABI without hardcoding
  • Get the cached off-chain metadata about a specific loan such as it’s description
  • Deploy and read loans straight to and from the Ethereum blockchain

Here’s an example showing the basic functionality, and documentation right here if you want to get your hands dirty right away.

My goal with this post is to expand on the example, explain the architecture of how the whole current ecosystem works together, and allow you to make your first application working with the Getline Network.

Architecture

Compared to many other decentralized ecosystems on Ethereum, the Getline Network, doesn’t really have a central Smart Contract. This means you’ll be deploying a new contract for each loan — to avoid bugs and hackers you’ll want to always have the newest version with latest patches and security. For making the developers’ job easier we’re providing a so-called metabackend service as well as it’s public endpoint — 0.api.getline.in. The metabackend serves the latest ABIs and Loan-Smart-Contract bytecode, additionally it holds cached meta-data about the loans themselves for a way to find loans without scraping the whole blockhain. Data such as the loan description and it’s address. It communicates using protobufs and gRPCWeb. We’re providing the endpoint for you convenience, but there’s nothing stopping you from deploying your own metabackend in your own controlled environment.

Getline.ts abstracts most of the metabackend functionality, requiring only it’s endpoint to be provided during initialization.

After getting the data from the metabackend, Getline.ts works directly with the Ethereum node provided by the user, through means of Web3. It deploys and talks directly with the loans already existing on the blockchain.

Both of those services are abstracted so that you, the user of Getline.ts, can think and work with only abstract loan objects and promises, without the need of working with the services themselves.

Loan object

Loans themselves work on ERC20 Tokens. To work they need two tokens, one is collateral which the borrower leaves on the table for the investors to take should they fail to repay the loan, and then there’s the lent token itself. This enables mix and match of what both the borrower and the loaner want to do, for example: the loaner might have long-term options in a startup, but needs a short-term money loan, so he requests Euro Stable Coin and in return freezes his options in the startup. Additional features of the network such as a community of credit scoring and regulatory entities will require the use of GET tokens as collateral in the future, but for the basic functionality, such as a direct 1 to 1 loan, any token can work.

All the money and logic of the loan itself are handled in the blockchain, so that you can trust that (except for the bugs), no one can cheat either party out of the agreed-on contract. Additional information, such as a long description are held outside of the blockchain (preferably in the metabackend) to save on fees.

Repayment

Currently the loans are an all-or-nothing scenario. We’ve been experimenting with credit lines in the past (GetLine, get it?), but we’ve reached a conclusion that there’s a bigger need for simplified loans with a simple repayment option. This means that the borrower needs to repay the loan in full before the default date, otherwise the loan is marked as failed and the collateral is lost.

Deadlines

Currently the loans on the blockchain estimate fundraising and default dates by counting elapsed blocks in the blockchain, we’re currently moving into time-stamps, and so we’ve abstracted any block counting in the getline.ts itself, and decided to work with dates instead, converting into an estimated number of blocks internally for the time being. Just keep in mind the deadline might float a bit from what you expected until we change the deadline methods.

API

Whole Getline.ts APIs are Promise-based. We’re using native Promises of Typescript and ES6 so if your environment doesn’t support them, you’ll need to polyfill them back in.

We’re strong advocates of async and await coding style, and that’s what we’re using in most situations, both internally and in our examples.

Creating a new loan

Currently we’re in a demo phase, meaning we’re explicitly not allowing you to use any other tokens and network from the infinite-supply of Test tokens and the Rinkeby network. This is for your own safety as the code might still be unstable and the tokens might be lost in the process.

Getting a new loan is very simple. You need to specify it’s description, how much tokens you want to borrow, on what kind of percentage, and how long will you be waiting for investors, and how long will they be waiting for you to pay the loan back. Additionally there is a second step in the process, transferring collateral requires setting allowance on the token itself and then notifying the loan, and since those are two additional transactions in the blockchain, we’ve decided to explicitly make it a second operation in code.

Getting user loans

Now, we’ve created the loan, we would like to get a list of all the loans of a user. Since each loan is a separate contract, it’s hard to find the list without scrapping the blockchain, so we hold that data in the metabackend for easy access.

As you can see in the documentation, the loan object has multiple properties allowing you to understand the state of the loan. If the object is newly created, accessing any of the properties will reload the state from the blockchain, taking some time, and afterwards, each access to the property will be instant due to caching in the client side. If you want to separate the loading or need to reload for UX reasons or due to other external events, we’re providing you with an explicit updateStateFromBlockchain() call that reloads the cache.

Future

Currently the API is usable, but it’s not stable yet — we will be changing it for better usability in the near future. Additionally we’re also working on a small front-end for the library, allowing any user to click-through their own loans without the need to understand development. The front-end works as our test-bed for getline.ts, allowing us to pinpoint major things that require improvements.

Getting involved

We’ll be happy to get to know you, understand your use case, and help you with any development work you’re doing in the Getline Network. You can reach the dev team in three ways:

  • Talk with us in the Getline’s RocketChat in the #dev channel. I can be found there as @ritave
  • Report any issues and suggestions you might have in the main repository on Github
  • For more business related inquires, we’re also monitoring the hello@getline.in e-mail account. Development inquires sent there will take longer than any other channel though.

If you enjoy our articles, please like and follow us on Facebook and Twitter.
Also, join our Rocket chat if you’re interested in contributing to our platform.

--

--