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

# Privy with AgentKit

> Give an AI agent a Privy server wallet and yield.xyz AgentKit: the agent builds transactions through MCP, and Privy signs them under policies, autonomously or with human approval.

This guide sets up an AI agent that discovers yields, enters and exits positions, and claims rewards with a Privy server wallet. yield.xyz [AgentKit](/documentation/ai-agents/agentkit/index) builds the unsigned transactions through the [MCP server](/documentation/ai-agents/mcp-server), and Privy creates the wallet, enforces policies and signs. The two never overlap: yield.xyz never signs, and Privy never builds transactions.

The same setup runs in production with real funds, and covers DeFi, staking and tokenized real-world assets, including RWA eligibility checks, subscription and redemption.

## Resources

* [AgentKit on GitHub](https://github.com/stakekit/agentkit), the `yield-xyz-agentkit-privy` skill and plugin
* [Privy agentic wallets](https://docs.privy.io/recipes/agent-integrations/agentic-wallets)
* [Privy Intents API](https://docs.privy.io/transaction-management/overview), for human approvals

## What the agent can do

* Search and compare yields across networks on live rate, TVL, rate history and risk
* Enter and exit staking, lending, vault and RWA positions
* Rebalance and rotate between strategies
* Claim rewards and complete pending actions
* Monitor a portfolio

It does this through the AgentKit MCP tools. The agent never calls the REST API directly.

| Tool | Purpose |
| - | - |
| `yields_get_all` | Search and filter yields by network, token, type or provider |
| `yields_get` | Full metadata for one yield |
| `yields_get_validators` | Validator options for delegation-based yields |
| `yields_get_risk` | The aggregate risk rating for a yield |
| `yields_get_reward_rate_history`, `yields_get_tvl_history` | Historical rate and TVL time series |
| `yields_get_kyc_status` | A wallet's KYC status for a permissioned yield |
| `yields_get_balances` | Balances and pending actions |
| `actions_enter`, `actions_exit`, `actions_manage` | Build transactions to enter, exit or complete a pending action |
| `actions_get`, `actions_get_all` | One action, or a wallet's past and pending actions |
| `get_transaction`, `submit_hash` | Poll a transaction, and report a broadcast hash |
| `networks_get_all`, `providers_get_all` | Supported networks and protocols |

See [MCP server](/documentation/ai-agents/mcp-server) for every tool's inputs.

### RWA eligibility

Before entering an RWA position, the agent checks eligibility. For a permissioned issuer it checks the wallet's KYC status: if the wallet is approved it builds and submits the transaction, and if not it shows the issuer's onboarding URL and stops, so nothing is sent from a wallet that is not allowlisted. For an open-access issuer it confirms jurisdiction eligibility and proceeds.

## Prerequisites

* A Privy app with API credentials from the [Privy dashboard](https://dashboard.privy.io/), with `PRIVY_APP_ID` and `PRIVY_APP_SECRET` set as environment variables, and optionally `PRIVY_WALLET_ID` for an existing wallet
* An agent such as [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview), Cursor or Codex CLI
* A Privy Enterprise plan, for the semi-autonomous workflow only

The skill does not create Privy credentials: configure Privy in the agent's environment first.

## Install

<Tabs>
  <Tab title="Claude Code plugin">
    ```bash theme={null}
    /plugin marketplace add stakekit/agentkit
    /plugin install yield-xyz-agentkit-privy@agentkit
    ```
  </Tab>

  <Tab title="Skill">
    ```bash theme={null}
    npx skills add https://github.com/stakekit/agentkit
    ```

    Pick `yield-xyz-agentkit-privy` and your agent (Claude Code, Cursor or Codex CLI). The skill is linked into the project at `.agents/skills/yield-xyz-agentkit-privy`.
  </Tab>
</Tabs>

Open the agent in the project directory and run:

```
Set up the yield-xyz-agentkit-privy skill
```

The skill checks your Privy credentials and asks which workflow to use.

## Choose a workflow

| | Autonomous | Semi-autonomous |
| - | - | - |
| **How it signs** | The agent signs and broadcasts through Privy's wallet RPC endpoint | Every transaction is submitted as an intent; an approver approves it on the Privy dashboard |
| **Controls** | Policies enforced inside Privy's TEE | Policies plus human approval of each transaction |
| **Privy plan** | Any | Enterprise |

### Autonomous

<Steps>
  <Step title="Verify credentials">
    The skill checks that `PRIVY_APP_ID` and `PRIVY_APP_SECRET`, and optionally `PRIVY_WALLET_ID`, are set.
  </Step>

  <Step title="Register the MCP server">
    ```bash theme={null}
    claude mcp add --transport http yield-agentkit https://mcp.yield.xyz/mcp
    ```
  </Step>

  <Step title="Attach a policy (optional)">
    Choose conservative, balanced or none. Policies limit per-transaction spend, allowed chains and allowlisted protocols, and are enforced inside the TEE.
  </Step>

  <Step title="Create and fund the wallet">
    The skill creates the wallet, attaches the policy and shows the address. Send assets to it.
  </Step>

  <Step title="Give instructions">
    For example: `Deposit USDC into Aave V3 on Base.`
  </Step>
</Steps>

### Semi-autonomous

Each transaction becomes a Privy intent that a designated approver reviews on the Privy dashboard. Intents expire after 72 hours. Their statuses are `pending`, `executed`, `failed`, `expired`, `rejected` and `dismissed`.

<Steps>
  <Step title="Run the first three autonomous steps">
    Verify credentials, register the MCP server and choose a policy.
  </Step>

  <Step title="Confirm Enterprise prerequisites">
    The Enterprise plan is active, and the approver has been invited and completed MFA.
  </Step>

  <Step title="Create a key quorum">
    In the Privy dashboard, go to **Wallet Infrastructure**, **Authorization**, **New Key**, **Register Key Quorum Instead**. Give the Quorum ID to the agent, which verifies it with `GET /v1/key_quorums/{id}`.
  </Step>

  <Step title="Create the wallet">
    The skill creates the wallet with the key quorum as owner:

    ```
    POST /v1/wallets
      chain_type: "ethereum"
      owner_id: <key_quorum_id>
      policy_ids: [<policy_id>]
    ```
  </Step>

  <Step title="Set up webhooks (optional)">
    Under **Configuration**, **Webhooks**, register an HTTPS endpoint and enable `intent.created`, `intent.authorized`, `intent.executed` and `intent.failed`.
  </Step>
</Steps>

Each transaction then runs: the agent builds it through MCP, submits it as an intent, the approver approves it, Privy signs and broadcasts, and the agent polls until `executed` and reads the hash.

## Transaction flow

Every enter, exit or manage follows the same sequence:

1. `yields_get` to read the yield's argument schema
2. `actions_enter`, `actions_exit` or `actions_manage` to build the transactions, returned with `stepIndex`, `type` and `unsignedTransaction`
3. For each transaction, in `stepIndex` order:
   * **Autonomous:** `POST /v1/wallets/{id}/rpc` returns the hash
   * **Semi-autonomous:** `POST /v1/intents/wallets/{id}/rpc`, then poll until `executed`
4. `submit_hash` with each confirmed hash, and report the result

### EVM

Pass only the fields Privy accepts from the unsigned transaction:

```bash theme={null}
PRIVY_TX=$(echo "$UNSIGNED_TX" | jq '{from, to, value, data, nonce, type} | with_entries(select(.value != null))')

# Base is eip155:8453
curl -s -X POST "https://api.privy.io/v1/wallets/$PRIVY_WALLET_ID/rpc" \
  --user "$PRIVY_APP_ID:$PRIVY_APP_SECRET" \
  -H "privy-app-id: $PRIVY_APP_ID" \
  -H "Content-Type: application/json" \
  -d "{\"method\":\"eth_sendTransaction\",\"caip2\":\"eip155:8453\",\"params\":{\"transaction\":$PRIVY_TX}}"
```

### Solana

Privy takes the transaction as base64. A Solana `unsignedTransaction` can come back hex or base64 encoded depending on the yield; convert hex to base64 first:

```bash theme={null}
TX_BASE64=$(echo "$UNSIGNED_TX" | xxd -r -p | base64)

curl -s -X POST "https://api.privy.io/v1/wallets/$PRIVY_WALLET_ID/rpc" \
  --user "$PRIVY_APP_ID:$PRIVY_APP_SECRET" \
  -H "privy-app-id: $PRIVY_APP_ID" \
  -H "Content-Type: application/json" \
  -d "{\"method\":\"signAndSendTransaction\",\"caip2\":\"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\",\"params\":{\"transaction\":\"$TX_BASE64\",\"encoding\":\"base64\"}}"
```

See [Solana signing](/guides/transaction-signing/solana) for detecting the encoding.

### Ordering

Transactions run one at a time in `stepIndex` order, with the EVM nonce increasing for each. If one fails, the agent stops and reports the failure. The skill never changes amounts, recipients, fees or calldata inside an `unsignedTransaction`: only field names are adjusted for Privy's format.

## Error handling

| Error | Cause | What the agent does |
| - | - | - |
| `POLICY_VIOLATION` | The transaction breaks a policy limit | Reports which rule triggered and does not retry without instruction |
| `INSUFFICIENT_FUNDS` | The wallet lacks gas | Asks the user to add the native token |
| `FAILED` | The transaction failed onchain | Gives the hash for inspection and stops the remaining steps |

## What stays manual

| Step | Why |
| - | - |
| Funding the agent wallet | Needs an existing external wallet |
| Inviting the approver and completing MFA | Tied to a user account and device |
| Creating the key quorum | Needs a user ID; kept manual for clarity |
| Approving a pending intent | By design: that is the control |
| Upgrading to Enterprise and setting up webhooks | Done on the Privy dashboard |

## Next steps

<Columns cols={2}>
  <Card title="AgentKit" icon="puzzle-piece" href="/documentation/ai-agents/agentkit/index">
    Plugins and skills for other agents and wallets.
  </Card>

  <Card title="Guardrails" icon="shield-halved" href="/documentation/ai-agents/agentkit/guardrails">
    What AgentKit checks before any transaction is built.
  </Card>

  <Card title="MCP server" icon="server" href="/documentation/ai-agents/mcp-server">
    Every tool and its inputs.
  </Card>

  <Card title="RWAs" icon="landmark" href="/documentation/earn/rwas/index">
    Issuers, eligibility and redemption timing.
  </Card>
</Columns>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.