Skip to main content
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.

API Key

Get your API key at Deframe

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.
JavaScript
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.docs.forEach(s => {
  console.log(`${s.slug}${s.protocol} on ${s.network} — APY: ${s.apy}%`)
})
{
  "docs": [
    {
      "_id": "679044af61866a32dd2d39e9",
      "slug": "aave-usdc-polygon",
      "name": "Aave USDC Lending",
      "protocol": "Aave",
      "network": "polygon",
      "asset": {
        "symbol": "USDC",
        "contract": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
        "decimals": 6
      },
      "apy": 4.82,
      "tvl": "48000000",
      "paused": false,
      "fee": "10"
    }
  ]
}
Use slug (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.
JavaScript
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
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.
ethers.js
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!')
viem
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.
JavaScript
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}%`)
})

console.log(`Total Balance (USD): $${wallet.summary.totalUnderlyingBalanceUSD}`)
cURL
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": 4.82
      },
      "strategy": {
        "id": "aave-usdc-polygon",
        "assetName": "USDC",
        "protocol": "aave",
        "network": "polygon"
      }
    }
  ],
  "summary": {
    "totalUnderlyingBalanceUSD": 10.05
  }
}
Call this endpoint periodically to track how your user’s position grows over time.

Next Steps