defire.io
Quick Start
Operations
Security
Library
Search…
Introduction
DeFi Operations
Quick Start
Security
Smart Contracts
Library
Overview
Getting started
Operations
Accounts
Portfolios
Utils
Advanced
Powered By
GitBook
Quick Start
This section shows code examples on how to get started in different languages using Defire's libraries.
JavaScript & Node
1.
Install the library.
1
npm install defire
Copied!
2.
Create an Ethereum account and fund it with some
Rinkeby ethers
.
3.
Initialize Defire library with that Ethereum account.
1
const
defire
=
Defire
({
2
address
:
"[INSERT ADDRESS OF ETHEREUM ACCOUNT]"
,
3
web3js
:
web3
4
},
{
network
:
"rinkeby"
}
5
);
Copied!
4.
Buy Some DAI in Uniswap
1
const
operationBuy
=
new
defire
.
Operations
.
Uniswap
.
Trade
.
ETH
.
For
.
DAI
({
2
amountETH
:
"500000000000000000"
// 0.5 ETH
3
});
4
await
defire
.
actions
.
execute
(
operationBuy
);
Copied!
5.
Get your current DAI balance
1
const
balance
=
await
defire
.
query
.
balance
(
defire
.
Assets
.
DAI
);
Copied!
6.
Lend all your DAI in Compound
1
const
operationLend
=
new
defire
.
Operations
.
Compound
.
Lend
.
DAI
({
2
amountDAI
:
balance
// 100% of DAI balance
3
});
4
await
defire
.
actions
.
execute
(
operationLend
);
Copied!
Congrats! You have bought DAI and lent it with a few lines of code.
😃
Consider using a
portfolio
. Check why they
are safer
.
Previous
DeFi Operations
Next
Security
Last modified
2yr ago
Copy link