Interact with DeFi from your browser console

Every Javascript Developer can be a Solidity Developer now

Interact with DeFi from your browser console

You don’t need to learn Solidity to build on Ethereum. We recently launched a DSA platform, which lets you use JavaScript to cast complex DeFi spells that handle the Solidity smart contracts. This means every JavaScript Developer can now be a Smart Contract Developer!

This is the first post in a multi-post tutorial! I plan to write a series of articles, specially curated for Javascript developers to start writing code to build amazing applications on DeFi.


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.

Step 1 — Set up an Account ⚙️

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.

Step 2 - Cast Spells 🔮

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:

  • Withdraw DAI from Maker DSR.
  • Lend DAI on Compound.

But guess what, both these steps can be executed in just a single step through DSA. I'll add 2 spells and execute.

Such types of cross protocol transactions need Smart Contract Development but with DSA platform, you can string together any number of transactions with just JavaScript. So Cool.

There you go! You’ve just moved DAI from MakerDAO DSR to Compound.

Step 3 — View Positions 🔍

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:

await dsa.compound.getPosition(address);

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.

You did it 🎉

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.

We're all ears and would like to invite everyone to join our Telegram user group or developers group. You can also reach out to us on Discord, Twitter or email.

Written by Vishva Dave