In this very first tutorial, you will learn to make a simple DeFi transaction with the help of DeFi Smart Account (DSA), and run basic operations like saving DAI on MakerDAO DSR to earn interest.
To get up and running within few seconds, I'll illustrate the whole process on my browser console on our docs website. Yes, you can get started right from your browser console. Feel free to follow me along - you can also perform the similar operations on dapps or nodejs environment using our SDK.
To get started, you need to have a web3 wallet like Metamask. If not, consider reading my previous article on how to get started with DeFi.
First, you will need to create a DSA (DeFi Smart Account), a smart contract account where you store your token assets which acts as a medium to interact with DeFi protocols.
You can create this account directly from the browser console via the dynamical web3 integration for developers. Head on to Setup Account on our docs, and run the build() function (as show below) - it returns a transaction hash which you can track on etherscan.
Remember to use await before running a function because few functions are asynchronous, and to complete the process of asynchronous functions; we use await to block the code until the function returns the data.
Note, if you already have a DSA, you can run the getAccounts() function to fetch your account(s). This will return all the DSAs owned by your ethereum address. Remember, DSA is a smart contract, so each DSA also has its unique address.
Once an account is created, make sure to specific the account to carry out further transactions, use setInstance() to configure that account, as shown below:
That's it. Now that your account is set up, let's move on to the next section.
Let’s start with the most straightforward DeFi operation — Save DAI and earn interest.
As the name DeFi implies, everything works in a decentralised manner; all transactions are managed by publicly available code (known as smart contracts) on Ethereum Blockchain. There are several financial protocols — MakerDAO is one of the core protocols — it allows you to save DAI (a USD pegged stable-coin) and continuously earn interest.
Now, I'll deposit 100 DAI in DSR by merely calling the following Spell.
After the transaction is confirmed, cross check your position by getting DSR positions.
But wait, the interest rate in DSR is ZERO. Let's find another protocol to earn interest for better opportunity.
Here we will be using Compound Finance, a decentralised platform that allows users to lend and borrow cryptocurrencies. Let's move your DAI from Maker DSR to Compound cDAI, which involves 2 steps:
But guess what, both these steps can be executed in just a single step through DSA. I'll add 2 spells and execute.
There you go! You’ve just moved DAI from MakerDAO DSR to Compound.
In the Resolvers section in the documentation, we've added simple ways to get position details of all the connectors, for better usability. Just run:
This is what will be displayed (or image from the console)
Note: Alternatively, you can also go to our new portal to check your positions.
The unprecedented rise of decentralized finance, and their underpinning blockchain technology (especially Ethereum), have taken the world by storm — and potentially could disrupt the existing financial giants and give access to the areas with no/less financial access.
That’s all I got. Let me know if you’ve any ideas.