Getting Started with ThirdFi, a Developer Guide
April 24, 2023
Compared to traditional financial systems, DeFi solves many problems in the current system. But DeFi is not easy and building a DeFi app from scratch will take months of development and rigorous testing. As a result of these issues, companies and users suffer heavy losses in the case of a malfunction.
Here comes ThirdFi, which provides unified framework to build DeFi apps on it. ThirdFi provides a middleware to build products on top of it’s API’s, SDK’s and developer tools. Developers and startups can utilize these tools to build secure applications faster.
ThirdFi provides support for blockchain networks including Ethereum, Polygon, BNB Chain, Avalanche, Arbitrum, Optimism, and KCC. Additionally, ThirdFi has already established deep partnerships with top DEXes, such as Uniswap, Sushiswap, Aave, PancakeSwap, TraderJoe, QuickSwap, Velodrome, and more.
For authentication, Thirdfi uses two keys
- Sandbox/API Key: This key is used for API authentication.
- Client Secret Key: It is used to generate the signature/hash and the hash is used in the headers when calling the API.
Step by Step guide for building on ThirdFi
1. Create an account on https://app.thirdfi.org/ and you will be redirected to the dashboard like this below.
2. From the setting menu, select sandbox environment for testing purposes. You can do the same with ‘API setup’ instead of selecting ‘Sandbox’ environment.
3. From the dashboard, click on ‘Create New Sandbox Key’ to get an API Key and the Secret. Save these keys and keep them secret as these will be used to make API calls.
5. Our API uses a RESTful interface and uses GET, POST, PATCH and DELETE methods.
6. Below is an example of using the “Get Currency Price” API which uses the “POST” request in Postman.
- Postman Workspace
- URL – It is the API URL on which the request will be made.
- TimeStamp – It is the current time calculated in seconds from, check unixtimestamp.com.
- Body Data – This contains the request body which is used by the API to process the request internally.
- Base String – It is updated every time as it contains the timestamp and body in it.
Three API headers are used in ThirdFi API requests and all of them are required to successfully make an API request. In Postman, we have already added a pre-script to load the API headers but we need to calculate them programmatically. The headers are:
- x-sec-key : ‘API KEY’
- x-sec-ts : ‘Timestamp’
- x-sec-sign : ‘Hash Value’
The Hash value is calculated using the HMAC-SHA-256 function which takes two inputs, one is the baseString and the other is the SECRET key.
Libraries Used to run the code.
- Axios – Promise-based API to implement HTTP requests.
ThirdFi also provides webhooks, to get updates based on the API Calls. Webhooks send automated JSON objects based on an event, here we send a response back whenever a transaction is done.
To setup webhooks, you need an endpoint URL to capture the response, you can use this free tool to test our webhook – https://webhook.site/
After you have added the webhook, make an API request and make a transaction to see what the response is. You can also see the response in the developer dashboard too, go to Developer Tools -> Webhook events to check it.
Let’s test it, using the “Create Swap Session” API here. Every webhook will have an event type to differentiate between different responses. Here you can find different responses from the webhooks – https://thirdfi.readme.io/reference/webhook-object
ThirdFi makes it easy to build DeFi apps. We provide an infrastructure to make Decentralised finance easy and secure. With the Customer API, developers can customize the user experience. Currently, we have the Borrow/Lending API, Swapping API, Fiat-to-crypto API and more, providing decentralised services.