# Set up Cardano staking with the API

To set up staking on a Cardano ledger, you need to do the following:

1. Register a staking address.
2. Delegate staking to a stake pool.


You can also do the following:

- Unregister a staking address.
- Withdraw staking rewards: The accumulated rewards are automatically delegated. You can withdraw the rewards without affecting your staking amount, which still stays in the stake pool. However, you cannot withdraw rewards if the address does not have a minimum amount of non-rewarded currency.


## Prerequisites

To perform staking tasks on Cardano, you need the following:

| Prerequisite | Additional information |
|  --- | --- |
| An account on a Cardano ledger from which to initiate the transactions | [View account details](/pt-br/products/custody/accounts-and-assets/accounts/manage-accounts-api#view-account-details) |
| Enough funds in the account to cover the transaction fees and the amount | [Check account balances](/pt-br/products/custody/accounts-and-assets/accounts/manage-accounts-api#check-account-balances) |
| The following new IDs, in a standard UUID format:A transaction order IDAn intent ID |  |


## Perform staking tasks

System change process
All new requests to change the system state follow the same process. To familiarize yourself with this process first, see [Manage intents and approvals](/pt-br/products/custody/governance/intents/manage-intents-and-approvals).

To perform staking tasks on Cardano, follow the steps in [Manage intents and approvals](/pt-br/products/custody/governance/intents/manage-intents-and-approvals), with a payload similar to one of the following examples.

The SDK examples assume a configured client. See [Integrate via SDK](/pt-br/products/custody/get-started/integrate-via-sdk). Each SDK method builds the operation, submits the intent, and returns a pending intent. To track the intent, call `waitAccepted` and `waitExecuted` (`wait_accepted` and `wait_executed` in Python). The Java examples pass `null` for `ledgerId` and `customProperties`, and reuse the `feeStrategy` from the first example.

### Payload examples

#### Register a staking address

API
```json
{
    "payload": {
        "id": "f49a4914-a590-4977-b340-205f07f5bc6a",
        "accountId": "416dcc47-b60c-49fb-be8e-ca7b8a8144ba",
        "parameters": {
            "operation": {
                "type": "RegisterStaking"
            },
            "feeStrategy": {
                "priority": "Medium",
                "type": "Priority"
            },
            "maximumFee": "10000",
            "type": "Cardano"
        },
        "description": "Cardano register staking",
        "customProperties": {},
        "type": "v0_CreateTransactionOrder"
    }
}
```

TypeScript
```typescript
const pending = await client.transactions.cardano.registerStaking(accountId, {
  feePriority: 'Medium',
  maximumFee: '10000',
});
```

Java
```java
import com.ripple.custody.PendingIntent;
import com.ripple.custody.models.CoreCardanoFeeStrategyPriority;
import com.ripple.custody.models.CoreFeePriority;

CoreCardanoFeeStrategyPriority feeStrategy =
    new CoreCardanoFeeStrategyPriority().priority(CoreFeePriority.MEDIUM);

PendingIntent pending = client.transactions()
    .cardanoRegisterStaking(domainId, accountId, null, feeStrategy, "10000", null);
```

Python
```python
pending = client.transactions.cardano.register_staking(
    account_id, fee_priority="Medium", maximum_fee="10000"
)
```

For a program that builds and submits these operations, see example `53` (advanced chain operations) in TypeScript or Python. To get the examples, see [Examples](/pt-br/products/custody/developer-experience/sdks#examples).

Fields of the `payload` block to note are as follows:

| Field | Description |
|  --- | --- |
| `accountId` | Internal account ID of an existing Cardano account in Ripple Custody (Vault). |
| `parameters.operation.type` | `RegisterStaking` |
| `parameters.feeStrategy` | The fee strategy to use for the transaction. For more information, see [Fee strategy and maximum fee](/pt-br/products/custody/transactions/reference#fee-strategy-and-maximum-fee). |
| `parameters.maximumFee` | The maximum fee, in lovelace. For more information, see [Fee strategy and maximum fee](/pt-br/products/custody/transactions/reference#fee-strategy-and-maximum-fee). |
| `parameters.type` | Ledger type, in this case `Cardano`. |
| `type` | `v0_CreateTransactionOrder` |


#### Unregister a staking address

API
```json
{
    "payload": {
        "id": "f49a4914-a590-4977-b340-205f07f5bc6a",
        "accountId": "416dcc47-b60c-49fb-be8e-ca7b8a8144ba",
        "parameters": {
            "operation": {
                "type": "UnregisterStaking"
            },
            "feeStrategy": {
                "priority": "Medium",
                "type": "Priority"
            },
            "maximumFee": "10000",
            "type": "Cardano"
        },
        "description": "Cardano unregister staking",
        "customProperties": {},
        "type": "v0_CreateTransactionOrder"
    }
}
```

TypeScript
```typescript
const pending = await client.transactions.cardano.unregisterStaking(accountId, {
  feePriority: 'Medium',
  maximumFee: '10000',
});
```

Java
```java
PendingIntent pending = client.transactions()
    .cardanoUnregisterStaking(domainId, accountId, null, feeStrategy, "10000", null);
```

Python
```python
pending = client.transactions.cardano.unregister_staking(
    account_id, fee_priority="Medium", maximum_fee="10000"
)
```

#### Delegate staking to a staking pool

API
```json
{
    "payload": {
        "id": "f49a4914-a590-4977-b340-205f07f5bc6a",
        "accountId": "416dcc47-b60c-49fb-be8e-ca7b8a8144ba",
        "parameters": {
            "operation": {
                "poolId": "pool1vf8ukuvdn7kv0hxgm23utjkkw5ugdhwfdrxy56l2t6wvxezspyu",
                "type": "DelegateStaking"
            },
            "feeStrategy": {
                "priority": "Medium",
                "type": "Priority"
            },
            "maximumFee": "10000",
            "type": "Cardano"
        },
        "description": "Cardano delegate staking",
        "customProperties": {},
        "type": "v0_CreateTransactionOrder"
    }
}
```

TypeScript
```typescript
const pending = await client.transactions.cardano.delegateStaking(accountId, {
  poolId: 'pool1vf8ukuvdn7kv0hxgm23utjkkw5ugdhwfdrxy56l2t6wvxezspyu',
  feePriority: 'Medium',
  maximumFee: '10000',
});
```

Java
```java
PendingIntent pending = client.transactions().cardanoDelegateStaking(
    domainId,
    accountId,
    null,
    "pool1vf8ukuvdn7kv0hxgm23utjkkw5ugdhwfdrxy56l2t6wvxezspyu",
    feeStrategy,
    "10000",
    null);
```

Python
```python
pending = client.transactions.cardano.delegate_staking(
    account_id,
    pool_id="pool1vf8ukuvdn7kv0hxgm23utjkkw5ugdhwfdrxy56l2t6wvxezspyu",
    fee_priority="Medium",
    maximum_fee="10000",
)
```

Fields of the `payload` block to note are as follows:

| Field | Description |
|  --- | --- |
| `accountId` | Internal account ID of an existing Cardano account in Ripple Custody (Vault). |
| `operation.poolId` | ID of the pool to which to delegate staking. Must be in Bech32 format. |
| `operation.type` | `DelegateStaking` |
| `parameters.feeStrategy` | The fee strategy to use for the transaction. For more information, see [Fee strategy and maximum fee](/pt-br/products/custody/transactions/reference#fee-strategy-and-maximum-fee). |
| `parameters.maximumFee` | The maximum fee, in lovelace. For more information, see [Fee strategy and maximum fee](/pt-br/products/custody/transactions/reference#fee-strategy-and-maximum-fee). |
| `parameters.type` | Ledger type, in this case `Cardano`. |
| `type` | `v0_CreateTransactionOrder` |


#### Withdraw staking rewards

API
```json
{
    "payload": {
        "id": "f49a4914-a590-4977-b340-205f07f5bc6a",
        "accountId": "416dcc47-b60c-49fb-be8e-ca7b8a8144ba",
        "parameters": {
            "operation": {
                "amount": "100000",
                "type": "WithdrawRewards"
            },
            "feeStrategy": {
                "priority": "Medium",
                "type": "Priority"
            },
            "maximumFee": "10000",
            "type": "Cardano"
        },
        "description": "Cardano withdraw rewards",
        "customProperties": {},
        "type": "v0_CreateTransactionOrder"
    }
}
```

TypeScript
```typescript
const pending = await client.transactions.cardano.withdrawRewards(accountId, {
  amount: '100000',
  feePriority: 'Medium',
  maximumFee: '10000',
});
```

Java
```java
PendingIntent pending = client.transactions()
    .cardanoWithdrawRewards(domainId, accountId, null, "100000", feeStrategy, "10000", null);
```

Python
```python
pending = client.transactions.cardano.withdraw_rewards(
    account_id, amount="100000", fee_priority="Medium", maximum_fee="10000"
)
```

When the transaction order is successfully approved, Ripple Custody (Vault) does the following:

- Creates a transaction, to broadcast the details on the blockchain.
- Creates one or more transfers, to represent the separate amounts associated with the transaction, such as the cryptocurrency amount and the fees.