# Delegation to a Cardano Staking Pool

To delegate ADA, you will need:

- `delegator_address`: The wallet from which the ADA will originate
- `validator_address`: The validator address to which the ADA will be delegated

Cardano has specific requirements for staking account registration:

- If the delegator has already posted a staking key registration certificate and a delegation certificate for their staking key, the Staking API will create a delegation transaction.
- If registration by the delegator is still required, the Staking API can create and broadcast the registration transaction.

> 📘
>
> ### Note  
> Cardano has no unbonding period; any delegated balance is free to be transferred at any time.
> 
> Delegation on Cardano differs from other networks in that the entire balance of the delegator address is delegated, rather than a portion of the balance. Delegating more ADA is just a matter of transferring funds into the delegating wallet, the balance of which will be delegated without further action.
>
> Undelegating ADA only requires transferring that amount out of the delegating wallet.

> ❗️
> ### Blockfrost Projects  
> To use Cardano with the Staking API, you must first add a Blockfrost Project ID to your account using the Blockfrost Projects endpoint.

## Create New Staking Flow
To initiate the delegation process, create a new flow with a `POST` request to `/flows`.

### URL
`https://api.figment.io/flows`

### Parameters
- `protocol\*`: `string` Protocol this flow operates on (ex. `cardano`).
- `network\*`: `string` Network this flow operates on (ex. `preprod`).
- `operation\*`: `string` The operation to perform (ex. `staking`).

### Example JSON Request
```json
{
  "protocol": "cardano",
  "network": "preprod",
  "operation": "staking"
}
```

### Response
- `id`: `string` ID of the flow.
- `operation`: `string` The Staking API operation being performed by this flow.
- `state`: `string` The current state of the flow.
- `actions`: `array` It includes the `name` & `inputs` of all next possible actions.

- `assign_staking_data`: Use this action to generate a delegation transaction to stake ADA.

- `delegator_address`: The delegating address, where ADA is being staked from.
    - `validator_address`: Cardano validator address or staking pool address.
- `data`: `object` Flow & transaction data.

### Example Response JSON
```json
{
  "id": "1c993340-0f63-4516-855a-b71dcd2715de",
  "operation": "staking",
  "state": "initialized",
  "actions": [
    {
      "name": "assign_staking_data",
      "inputs": [
        {
          "name": "delegator_address",
          "display": "Delegator Address",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": null
        },
        {
          "name": "validator_address",
          "display": "Validator Address",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": null
        }
      ]
    }
  ],
  "data": {
    "delegator_address": null,
    "validator_address": null,
    "registered": null,
    "register_transaction": null,
    "delegate_transaction": null
  },
  "protocol": "cardano",
  "network": "preprod",
  "created_at": "2023-02-17T23:15:19.309Z",
  "updated_at": "2023-02-17T23:15:19.309Z"
}
```

## Assign Staking Data
To initiate either the registration transaction or delegate transaction, continue the flow with a `PUT` request to `/flows/[:flow_id]/next`.

### URL
`https://api.figment.io/flows/[:flow_id]/next`

### Example Request
```json
{
  "name": "assign_staking_data",
  "inputs": {
    "delegator_address": "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x",
    "validator_address": "pool1wn6a6f23ctq06udwhw27ravdpd6zcr7jlut3yez0wzdackz3222"
  }
}
```

### Example Response JSON
```json
{
  "id": "6f995c8a-08b7-43ff-9275-0ef8fc94bc26",
  "operation": "staking",
  "state": "register_tx_signature",
  "actions": [
    {
      "name": "refresh_register_tx",
      "inputs": []
    },
    {
      "name": "sign_register_tx",
      "inputs": [
        {
          "name": "transaction_payload",
          "display": "Transaction Payload",
          "description": "",
          "type": "signed_transaction",
          "validations": [
            {
              "type": "sign_payload",
              "options": {}
            }
          ],
          "array": false,
          "default_value": null,
          "signers": [
            "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x"
          ],
          "transaction_payload": "84a40081825820dac094796df4319dba24ecb71d109a274f7f4b96ada5eb2b5282f47027b0707700018182583900dd0276d1f55c2db7b6cc10777ce37a73cc657d59b8011e0ac40021f5a64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b871b0000000253db9117021a00028c29048182008200581ca64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b87a0f5f6"
        },
        {
          "name": "signatures",
          "display": "Signatures",
          "description": "",
          "type": "array_of_signatures",
          "validations": [],
          "array": true,
          "default_value": null,
          "element_type": "signature_data",
          "signers": [
            "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x"
          ],
          "transaction_payload": "84a40081825820dac094796df4319dba24ecb71d109a274f7f4b96ada5eb2b5282f47027b0707700018182583900dd0276d1f55c2db7b6cc10777ce37a73cc657d59b8011e0ac40021f5a64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b871b0000000253db9117021a00028c29048182008200581ca64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b87a0f5f6",
          "signing_payload": "33f750583301f5b298e7a4d9d42cd950be86ecd018f8df37e4fb58640d39e997",
          "inputs": [
            {
              "name": "account_address",
              "display": "Account Address",
              "description": "",
              "type": "string",
              "validations": [
                {
                  "type": "presence",
                  "options": {}
                }
              ],
              "array": false,
              "default_value": null
            },
            {
              "name": "signature",
              "display": "Signature",
              "description": "",
              "type": "string",
              "validations": [
                {
                  "type": "presence",
                  "options": {}
                }
              ],
              "array": false,
              "default_value": null
            }
          ]
        }
      ]
    },
    {
      "name": "confirm_register_tx_by_hash",
      "inputs": [
        {
          "name": "hash",
          "display": "Hash",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": null
        },
        {
          "name": "block_number",
          "display": "Block Number",
          "description": "",
          "type": "integer",
          "validations": [],
          "array": false,
          "default_value": null
        }
      ]
    }
  ],
  "data": {
    "delegator_address": "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x",
    "validator_address": "pool1wn6a6f23ctq06udwhw27ravdpd6zcr7jlut3yez0wzdackz3222",
    "registered": null,
    "register_transaction": {
      "raw": "84a40081825820dac094796df4319dba24ecb71d109a274f7f4b96ada5eb2b5282f47027b0707700018182583900dd0276d1f55c2db7b6cc10777ce37a73cc657d59b8011e0ac40021f5a64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b871b0000000253db9117021a00028c29048182008200581ca64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b87a0f5f6",
      "signing_payload": "33f750583301f5b298e7a4d9d42cd950be86ecd018f8df37e4fb58640d39e997",
      "signed": null,
      "hash": "33f750583301f5b298e7a4d9d42cd950be86ecd018f8df37e4fb58640d39e997",
      "status": null,
      "error": null,
      "signatures": null,
      "block_time": null
    },
    "delegate_transaction": null
  },
  "protocol": "cardano",
  "network": "preprod",
  "created_at": "2023-02-24T17:06:06.083Z",
  "updated_at": "2023-02-24T17:06:46.928Z"
}
```

## Submit Delegate Data
After collecting the required inputs, send a `PUT` request to `/flows/[:flow_id]/next` to proceed to the next step.

### Example Request
```json
{
  "name": "create_delegate_tx",
  "inputs": {
    "delegator_address": "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x",
    "validator_address": "pool1wn6a6f23ctq06udwhw27ravdpd6zcr7jlut3yez0wzdackz3222"
  }
}
```

### Example Response JSON
```json
{
  "id": "6f995c8a-08b7-43ff-9275-0ef8fc94bc26",
  "operation": "staking",
  "state": "delegate_tx_signature",
  "actions": [
    {
      "name": "refresh_delegate_tx",
      "inputs": []
    },
    {
      "name": "sign_delegate_tx",
      "inputs": [
        {
          "name": "transaction_payload",
          "display": "Transaction Payload",
          "description": "",
          "type": "signed_transaction",
          "validations": [
            {
              "type": "sign_payload",
              "options": {}
            }
          ],
          "array": false,
          "default_value": null,
          "signers": [
            "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x"
          ],
          "transaction_payload": "84a4008182582033f750583301f5b298e7a4d9d42cd950be86ecd018f8df37e4fb58640d39e99700018182583900dd0276d1f55c2db7b6cc10777ce37a73cc657d59b8011e0ac40021f5a64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b871b0000000253d8ee6a021a0002a2ad048183028200581ca64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b87581c74f5dd2551c2c0fd71aebb95e1f58d0b742c0fd2ff1712644f709bdca10082825820e64c0674e648699f8fa225632bfa1402d09dc3aa2e1f2b523702d2faac9d67d558401b5c035fa577f743dcc5f0b500d9a3c621aa17297d7a5824671be13c35f764c5e70ccd5d1cb26cb942d5f967214f0f8e1a5853b1c18e7fc6ac90b714a579ab0a8258208e1bdf6b1776a3cac2686e14130029b4544b9f004faa67992b107001b67dd993584027152598680a9e251bec230aca563f34aaf6e8403b630a395b2b62d35b873bc7121d4c026e3cff32c44194202003c3fc350753548645946baf61e65cbbd31003f5f6"
        },
        {
          "name": "signatures",
          "display": "Signatures",
          "description": "",
          "type": "array_of_signatures",
          "validations": [],
          "array": true,
          "default_value": null,
          "element_type": "signature_data",
          "signers": [
            "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x"
          ],
          "transaction_payload": "84a4008182582033f750583301f5b298e7a4d9d42cd950be86ecd018f8df37e4fb58640d39e99700018182583900dd0276d1f55c2db7b6cc10777ce37a73cc657d59b8011e0ac40021f5a64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b871b0000000253d8ee6a021a0002a2ad048183028200581ca64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b87581c74f5dd2551c2c0fd71aebb95e1f58d0b742c0fd2ff1712644f709bdca0f5f6",
          "signing_payload": "689c8172693b66d5a649d1bb8e7df8b5a83c828022910602c1e7815b88c1597a",
          "inputs": [
            {
              "name": "account_address",
              "display": "Account Address",
              "description": "",
              "type": "string",
              "validations": [
                {
                  "type": "presence",
                  "options": {}
                }
              ],
              "array": false,
              "default_value": null
            },
            {
              "name": "signature",
              "display": "Signature",
              "description": "",
              "type": "string",
              "validations": [
                {
                  "type": "presence",
                  "options": {}
                }
              ],
              "array": false,
              "default_value": null
            }
          ]
        }
      ]
    },
    {
      "name": "confirm_delegate_tx_by_hash",
      "inputs": [
        {
          "name": "hash",
          "display": "Hash",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": null
        },
        {
          "name": "block_number",
          "display": "Block Number",
          "description": "",
          "type": "integer",
          "validations": [],
          "array": false,
          "default_value": null
        }
      ]
    }
  ],
  "data": {
    "delegator_address": "addr_test1qrwsyak374wzmdakesg8wl8r0feucetatxuqz8s2csqzradxfu7p7cvhrg6eh374ps852jxq7qzgfjwgknn36ggkdwrsu6ae9x",
    "validator_address": "pool1wn6a6f23ctq06udwhw27ravdpd6zcr7jlut3yez0wzdackz3222",
    "registered": null,
    "register_transaction": {
      "raw": "84a4008182582033f750583301f5b298e7a4d9d42cd950be86ecd018f8df37e4fb58640d39e99700018182583900dd0276d1f55c2db7b6cc10777ce37a73cc657d59b8011e0ac40021f5a64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b871b0000000253d8ee6a021a0002a2ad048183028200581ca64f3c1f61971a359bc7d50c0f4548c0f00484c9c8b4e71d21166b87581c74f5dd2551c2c0fd71aebb95e1f58d0b742c0fd2ff1712644f709bdca10082825820e64c0674e648699f8fa225632bfa1402d09dc3aa2e1f2b523702d2faac9d67d558401b5c035fa577f743dcc5f0b500d9a3c621aa17297d7a5824671be13c35f764c5e70ccd5d1cb26cb942d5f967214f0f8e1a5853b1c18e7fc6ac90b714a579ab0a8258208e1bdf6b1776a3cac2686e14130029b4544b9f004faa67992b107001b67dd993584027152598680a9e251bec230aca563f34aaf6e8403b630a395b2b62d35b873bc7121d4c026e3cff32c44194202003c3fc350753548645946baf61e65cbbd31003f5f6",
      "signing_payload": "689c8172693b66d5a649d1bb8e7df8b5a83c828022910602c1e7815b88c1597a",
      "signed": null,
      "hash": "689c8172693b66d5a649d1bb8e7df8b5a83c828022910602c1e7815b88c1597a",
      "status": null,
      "error": null,
      "signatures": null,
      "block_time": null
    },
    "delegate_transaction": null
  },
  "protocol": "cardano",
  "network": "preprod",
  "created_at": "2023-02-24T17:06:06.083Z",
  "updated_at": "2023-02-24T17:12:40.672Z"
}
```
