> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privy.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrating Pods with Privy

Pods allows apps to access diversified DeFi yield strategies across multiple protocols through a single API. Apps fetch strategies from Pods and execute the returned transaction bytecodes using Privy wallets. This enables deposits into lending, staking, and protocol-native yield strategies without managing complex transaction flows.

## Resources

<CardGroup cols={2}>
  <Card title="Pods Docs" icon="arrow-up-right-from-square" href="https://docs.pods.finance" arrow>
    Official documentation for Pods strategies and API.
  </Card>

  <Card title="Starter repo" icon="github" href="https://github.com/pods-finance/pods-privy-integration" arrow>
    Full working example of Pods + Privy integration.
  </Card>
</CardGroup>

***

## Using Pods with Privy

For this walkthrough, the examples use the Aave USDT strategy on Polygon. The same patterns work across all Pods-supported strategies and networks—explore the complete list via the [Pods API](https://docs.pods.finance).

### Setup

Below is a minimal setup for the Privy provider. To customize the provider, follow the [Privy Quickstart](/basics/get-started/dashboard/create-new-app).

```tsx theme={"system"}
import {PrivyProvider} from '@privy-io/react-auth';

export function App() {
  return (
    <PrivyProvider appId="your-privy-app-id">{/* Your application components */}</PrivyProvider>
  );
}
```

### Configure Pods API access

Obtain your API credentials from the Pods Dashboard:

```tsx theme={"system"}
const PODS_API_URL = 'https://api.pods.finance';
const PODS_API_KEY = 'your-pods-api-key';
```

### List available strategies

Fetch the yield strategies available for users:

```tsx theme={"system"}
const fetchStrategies = async () => {
  const response = await fetch(`${PODS_API_URL}/strategies?limit=100`, {
    method: 'GET',
    headers: {
      'x-api-key': PODS_API_KEY
    }
  });

  const {data: strategies} = await response.json();
  return strategies;
};
```

Each strategy includes fields like `id`, `protocol`, `assetName`, `network`, and `availableActions`.

***

### Deposit into a yield strategy

<Steps>
  <Step title="1. Get the user's wallet address">
    ```tsx theme={"system"}
    import {useWallets} from '@privy-io/react-auth';

    const {wallets} = useWallets();
    const walletAddress = wallets[0]?.address;
    ```
  </Step>

  <Step title="2. Generate transaction bytecodes from Pods">
    Request the bytecodes needed to execute a deposit action:

    ```tsx theme={"system"}
    const strategyId = 'Aave-USDT-polygon';
    const action = 'lend';
    const amount = '1500000'; // 1.5 USDT (6 decimals)

    const response = await fetch(
      `${PODS_API_URL}/strategies/${strategyId}/bytecode?action=${action}&wallet=${walletAddress}&amount=${amount}`,
      {
        method: 'GET',
        headers: {
          'x-api-key': PODS_API_KEY
        }
      }
    );

    const bytecodeResponse = await response.json();
    ```

    The response contains an array of transactions to execute:

    ```tsx theme={"system"}
    type PodsBytecodeResponse = {
      feeCharged: string;
      metadata: {
        isCrossChain: boolean;
        isSameChainSwap: boolean;
        crossChainQuoteId: string;
      };
      bytecode: {
        to: string;
        value: string;
        data: string;
        chainId: string;
      }[];
    };
    ```
  </Step>

  <Step title="3. Execute the transactions with Privy">
    Use Privy's `useSendTransaction` to execute each bytecode:

    ```tsx theme={"system"}
    import {useSendTransaction} from '@privy-io/react-auth';

    const {sendTransaction} = useSendTransaction();

    const executePodsStrategy = async (bytecodeResponse: PodsBytecodeResponse) => {
      for (const tx of bytecodeResponse.bytecode) {
        await sendTransaction({
          to: tx.to as `0x${string}`,
          data: tx.data as `0x${string}`,
          value: BigInt(tx.value),
          chainId: Number(tx.chainId)
        });
      }
    };
    ```
  </Step>
</Steps>

***

### Check strategy position

Fetch the user's current position and APY for a strategy:

```tsx theme={"system"}
const fetchPosition = async (strategyId: string, walletAddress: string) => {
  const response = await fetch(`${PODS_API_URL}/strategies/${strategyId}?wallet=${walletAddress}`, {
    method: 'GET',
    headers: {
      'x-api-key': PODS_API_KEY
    }
  });

  const strategy = await response.json();
  return {
    apy: strategy.apy,
    avgApy: strategy.avgApy,
    position: strategy.position
  };
};
```

***

### Withdraw from a strategy

To withdraw, use the `withdraw` action and execute the returned bytecodes:

```tsx theme={"system"}
import {useSendTransaction} from '@privy-io/react-auth';

const {sendTransaction} = useSendTransaction();

const withdrawFromStrategy = async (strategyId: string, walletAddress: string, amount: string) => {
  const response = await fetch(
    `${PODS_API_URL}/strategies/${strategyId}/bytecode?action=withdraw&wallet=${walletAddress}&amount=${amount}`,
    {
      method: 'GET',
      headers: {
        'x-api-key': PODS_API_KEY
      }
    }
  );

  const bytecodeResponse = await response.json();

  for (const tx of bytecodeResponse.bytecode) {
    await sendTransaction({
      to: tx.to as `0x${string}`,
      data: tx.data as `0x${string}`,
      value: BigInt(tx.value),
      chainId: Number(tx.chainId)
    });
  }
};
```

***

## Pods EarnWidget

For a faster integration, Pods provides a pre-built `EarnWidget` component that handles strategy selection, deposits, and withdrawals with a built-in UI.

### Install the Pods SDK

```bash theme={"system"}
npm install pods-sdk @pods-sdk/components @reduxjs/toolkit react-redux redux permissionless
```

<Warning>
  If your app uses Vite, install the Node polyfills plugin and add it to `vite.config.ts`:

  ```bash theme={"system"}
  npm install --save-dev vite-plugin-node-polyfills
  ```

  ```ts theme={"system"}
  import {defineConfig} from 'vite';
  import {nodePolyfills} from 'vite-plugin-node-polyfills';

  export default defineConfig({
    plugins: [nodePolyfills()]
  });
  ```
</Warning>

### Configure the widget

```tsx theme={"system"}
import {PodsProvider, EarnWidget} from 'pods-sdk';
import {useSmartWallets} from '@privy-io/react-auth/smart-wallets';
import {usePrivy} from '@privy-io/react-auth';

const {user} = usePrivy();
const {client: smartWalletClient, getClientForChain} = useSmartWallets();

const config = {
  PODS_API_URL: 'https://api.pods.finance',
  PODS_API_KEY: 'your-pods-api-key',
  walletAddress: smartWalletClient?.account.address,
  userId: user?.id,
  globalCurrency: 'USD',
  globalCurrencyExchangeRate: 1,
  theme: {mode: 'dark', preset: 'default'}
};
```

### Implement the bytecode processor

The widget returns bytecode for the app to execute using Privy smart wallets:

```tsx theme={"system"}
import type {BytecodeTransaction, UpdateTxStatus} from 'pods-sdk';

const processBytecode = async (
  payload: {clientTxId: string; bytecodes: BytecodeTransaction[]; simulateError?: boolean},
  ctx: {updateTxStatus: UpdateTxStatus}
) => {
  ctx.updateTxStatus({type: 'HOST_ACK', clientTxId: payload.clientTxId});

  const chainId = Number(payload.bytecodes[0].chainId);
  const chainClient = await getClientForChain({id: chainId});

  const calls = payload.bytecodes.map((b) => ({
    to: b.to as `0x${string}`,
    data: b.data as `0x${string}`,
    value: BigInt(b.value)
  }));

  ctx.updateTxStatus({type: 'SIGNATURE_PROMPTED', clientTxId: payload.clientTxId});
  const txHash = await chainClient.sendTransaction({calls});
  ctx.updateTxStatus({type: 'TX_SUBMITTED', clientTxId: payload.clientTxId, txHash});
};
```

### Render the widget

```tsx theme={"system"}
<PodsProvider config={config} processBytecode={processBytecode}>
  <EarnWidget autoHeight />
</PodsProvider>
```

<Info>
  The EarnWidget requires [Smart Wallets](/wallets/using-wallets/evm-smart-wallets/overview) for
  transaction execution. Enable Smart Wallets in the [Privy Dashboard](https://dashboard.privy.io/)
  under Wallet infrastructure.
</Info>

***

## Key integration tips

1. **Handle token decimals**: The `amount` parameter must respect the token's decimal places. USDT and USDC use 6 decimals; most other tokens use 18.
2. **Execute transactions in order**: Pods may return multiple bytecodes for a single action. Execute them sequentially.
3. **Verify available actions**: Each strategy has an `availableActions` array. Check that the action exists before requesting bytecodes.
4. **Handle errors gracefully**: Wrap transaction execution in try/catch blocks to handle user rejection, insufficient funds, and network issues.

For advanced use cases, refer to the [Pods Docs](https://docs.pods.finance), or reach out in [Slack](https://privy.io/slack).
