> For the complete documentation index, see [llms.txt](https://dev.ada-anvil.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ada-anvil.io/guides/delegations.md).

# Delegations

## API Overview

Delegations in Cardano enable users to participate in the network without running infrastructure themselves. Stake pool delegations allow users to earn rewards by supporting the network's security, while DRep delegations empower users to participate in governance decisions. The Anvil API simplifies implementing both delegation types through a unified interface, letting applications offer these essential features without complex blockchain interactions.

| Type   | Purpose                            | Certificate Created |
| ------ | ---------------------------------- | ------------------- |
| `pool` | Delegate to stake pool for rewards | `StakeDelegation`   |
| `drep` | Delegate to DRep for governance    | `VoteDelegation`    |

## API Endpoint

**URL**: `https://preprod.api.ada-anvil.app/v2/services/transactions/build`\
**Method**: POST\
**Headers**: `Content-Type: application/json`, `x-api-key: YOUR_API_KEY`

## Request Format

```json
{
  "changeAddress": "addr_test1...", 
  "delegations": [
    {
      "type": "pool" | "drep",
      "address": "addr_test1...",
      "keyHash": "pool_id_or_drep_id"
    }
  ]
}
```

## Parameters

| Parameter       | Description                       | Required            |
| --------------- | --------------------------------- | ------------------- |
| `type`          | Either `"pool"` or `"drep"`       | Yes                 |
| `address`       | User's full address               | Yes                 |
| `keyHash`       | Pool ID or DRep ID                | Yes                 |
| `changeAddress` | Address for change                | Yes                 |
| `utxos`         | Array of UTXOs in CBOR hex format | Yes (in production) |

## Implementation Guides

{% content-ref url="/pages/9N5ko1j3NXCrFh8NoX5C" %}
[Delegate to a DRep](/guides/delegations/delegate-to-a-drep.md)
{% endcontent-ref %}

{% content-ref url="/pages/nph9znb6kA1L9wLPrwd0" %}
[Delegate to a Stake Pool](/guides/delegations/delegate-to-a-pool.md)
{% endcontent-ref %}

## Transaction Workflow

1. **Prepare**: Include delegation certificates in transaction
2. **Build & Sign**: Process transaction with proper certificates and signatures
3. **Submit**: Send to network (changes effective after current epoch)

## Best Practices

* **Verification**: Confirm pool/DRep IDs before delegation
* **Testing**: Use testnet before mainnet operations
* **Error Handling**: Implement robust handling for:
  * Invalid address formats
  * Unknown pool/DRep IDs
  * Insufficient funds
  * Missing signers

## Related Resources

* [Signing Transactions](https://github.com/Cardano-Forge/anvil-api/blob/main/docs/guides/transaction/signing-transaction.md)
* [Submitting Transactions](/guides/transaction/submit-transaction.md)
