This quickstart walks you through integrating a DeFi yield strategy into your
application. You’ll browse available strategies, generate deposit transaction
data, and execute it with your user’s wallet.
Wallet Have an Ethereum/Polygon wallet address and sufficient USDC balance
Ensure your wallet has sufficient USDC on Polygon and MATIC for gas fees.
Create a .env file:
DEFRAME_API_KEY = your-api-key
WALLET_ADDRESS = 0x...
PRIVATE_KEY = 0x...
POLYGON_RPC_URL = https://polygon-rpc.com
Never commit your .env file to version control. Add it to .gitignore.
Step 1: Browse Available Strategies
List all available yield strategies to find one for your use case.
import axios from 'axios'
const walletAddress = process . env . WALLET_ADDRESS // Your wallet address
const deframe = axios . create ({
baseURL: 'https://api.deframe.io' ,
headers: { 'x-api-key' : process . env . DEFRAME_API_KEY }
})
const { data : strategies } = await deframe . get ( '/strategies' )
strategies . data . forEach ( s => {
console . log ( ` ${ s . id } — ${ s . protocol } on ${ s . network } — APY: ${ ( s . apy * 100 ). toFixed ( 2 ) } %` )
})
{
"data" : [
{
"id" : "Aave-USDC-polygon" ,
"protocol" : "Aave" ,
"assetName" : "USDC" ,
"network" : "polygon" ,
"asset" : "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" ,
"assetDecimals" : 6 ,
"apy" : 0.0482 ,
"paused" : false ,
"fee" : "0" ,
"availableActions" : [ "lend" , "withdraw" ]
}
],
"pagination" : {
"totalRecords" : 5 ,
"limit" : 10 ,
"totalPages" : 1 ,
"page" : 1 ,
"hasPrevPage" : false ,
"hasNextPage" : false
}
}
Use id (e.g. Aave-USDC-polygon) as the strategy identifier in the next steps.
Step 2: Generate Deposit Bytecode
Request ready-to-execute transaction data for depositing into the strategy.
const { data : result } = await deframe . get ( '/strategies/aave-usdc-polygon/bytecode' , {
params: {
action: 'lend' ,
amount: '10000000' , // 10 USDC (6 decimals)
wallet: walletAddress
}
})
console . log ( 'Transactions to execute:' , result . bytecode . length )
curl -X GET "https://api.deframe.io/strategies/aave-usdc-polygon/bytecode" \
-H "x-api-key: $DEFRAME_API_KEY " \
-G \
--data-urlencode "action=lend" \
--data-urlencode "amount=10000000" \
--data-urlencode "wallet= $WALLET_ADDRESS "
{
"feeCharged" : "0" ,
"metadata" : {
"isCrossChain" : false ,
"isSameChainSwap" : false
},
"bytecode" : [
{
"to" : "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" ,
"data" : "0x095ea7b3..." ,
"value" : "0" ,
"chainId" : 137
},
{
"to" : "0x794a61358D6845594F94dc1DB02A252b5b4814aD" ,
"data" : "0x617ba037..." ,
"value" : "0" ,
"chainId" : 137
}
]
}
The response may contain multiple transactions (e.g. token approval + deposit).
Execute them in order.
Step 3: Execute Transactions
Sign and broadcast each transaction using your wallet library.
import { ethers } from 'ethers'
const provider = new ethers . JsonRpcProvider ( process . env . POLYGON_RPC_URL )
const wallet = new ethers . Wallet ( process . env . PRIVATE_KEY , provider )
for ( const tx of result . bytecode ) {
const transaction = await wallet . sendTransaction ({
to: tx . to ,
data: tx . data ,
value: tx . value || '0' ,
chainId: tx . chainId
})
console . log ( 'Transaction sent:' , transaction . hash )
const receipt = await transaction . wait ()
console . log ( 'Confirmed in block:' , receipt . blockNumber )
}
console . log ( 'Deposit successful!' )
import { createWalletClient , http } from 'viem'
import { polygon } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'
const account = privateKeyToAccount ( process . env . PRIVATE_KEY )
const client = createWalletClient ({
account ,
chain: polygon ,
transport: http ( process . env . POLYGON_RPC_URL )
})
for ( const tx of result . bytecode ) {
const hash = await client . sendTransaction ({
to: tx . to ,
data: tx . data ,
value: BigInt ( tx . value || '0' )
})
console . log ( 'Transaction sent:' , hash )
const receipt = await client . waitForTransactionReceipt ({ hash })
console . log ( 'Confirmed in block:' , receipt . blockNumber )
}
console . log ( 'Deposit successful!' )
Step 4: Check Your Position
After depositing, use the /wallets endpoint to check the current position and profit for your strategy.
const { data : wallet } = await deframe . get ( `/wallets/ ${ walletAddress } ` )
wallet . positions . forEach ( p => {
console . log ( `Strategy: ${ p . strategy . protocol } ${ p . strategy . assetName } on ${ p . strategy . network } ` )
console . log ( ` Current Position: ${ p . spotPosition . currentPosition . humanized } ${ p . spotPosition . currentPosition . symbol } ` )
console . log ( ` Principal: ${ p . spotPosition . principal . humanized } ${ p . spotPosition . principal . symbol } ` )
console . log ( ` Profit: ${ p . spotPosition . profit . humanized } ${ p . spotPosition . profit . symbol } ` )
console . log ( ` APY: ${ ( p . spotPosition . apy * 100 ). toFixed ( 2 ) } %` )
})
console . log ( `Total Balance (USD): $ ${ wallet . summary . totalUnderlyingBalanceUSD } ` )
curl -X GET "https://api.deframe.io/wallets/ $WALLET_ADDRESS " \
-H "x-api-key: $DEFRAME_API_KEY "
{
"positions" : [
{
"spotPosition" : {
"currentPosition" : {
"value" : "10048700" ,
"decimals" : 6 ,
"humanized" : "10.0487" ,
"symbol" : "USDC"
},
"profit" : {
"value" : "48700" ,
"decimals" : 6 ,
"humanized" : "0.0487" ,
"symbol" : "USDC"
},
"principal" : {
"value" : "10000000" ,
"decimals" : 6 ,
"humanized" : "10.00" ,
"symbol" : "USDC"
},
"underlyingBalanceUSD" : 10.05 ,
"apy" : 0.0482
},
"strategy" : {
"id" : "Aave-USDC-polygon" ,
"assetName" : "USDC" ,
"protocol" : "Aave" ,
"network" : "polygon" ,
"asset" : "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" ,
"assetDecimals" : 6
}
}
],
"summary" : {
"totalUnderlyingBalanceUSD" : 10.05
}
}
Call this endpoint periodically to track how your user’s position grows over time.
Next Steps
Check Positions Verify the deposit and monitor your user’s yield position
Withdraw Generate withdrawal transaction data
All Yield Guides Browse strategies, deposit, check positions, and withdraw
Add Swaps Also integrate token swaps into your app