API Reference

Delegate

Staking NEAR is a simple process. We will collect:

  • The delegating address
  • The signing public key
  • The validator address
  • The amount of NEAR to be staked
  • Optionally, a max gas amount (upper limit of the transaction fee to be paid)

Once the delegating transaction is confirmed on-chain, the delegation will immediately be active and earning staking rewards.

In the following guide we will illustrate how to stake NEAR.

Create New Staking Flow

To initiate the staking process, create a new flow with a POST request to /flows.

URL

https://api.figment.io/flows

Request

  • protocol* : string Protocol this flow operates on (ex. near).
  • network* : string Network this flow operates on (ex. mainnet).
  • operation* : string The operation to perform (ex. staking).
{
  "protocol": "near",
  "network": "testnet",
  "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.
    • create_delegate_tx : Use this action to generate a delegation transaction to stake NEAR.
      • validator_address : Figment validator address.
      • delegator_address : The delegating address.
      • delegator_pubkey : The public key of the signing account. Must start with ed25519:.
      • amount : The amount of NEAR to be delegated.
      • max_gas : Adjust if you wish to limit the possible transaction fee.
  • data : object Flow & transaction data.
{
  "id": "aeb7503c-27c8-4184-8537-8f4a77f694a9",
  "state": "initialized",
  "actions": [
    {
      "name": "create_delegate_tx",
      "inputs": [
        {
          "name": "delegator_address",
          "display": "Delegator Address",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            },
            {
              "type": "account_balance",
              "options": {
                "on": "with_on_chain_validations",
                "greater_than_or_equal_to": null
              }
            }
          ]
        },
        {
          "name": "delegator_pubkey",
          "display": "Delegator Pubkey",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ]
        },
        {
          "name": "validator_address",
          "display": "Validator Address",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            },
            {
              "type": "is_validator",
              "options": {
                "on": "with_on_chain_validations"
              }
            }
          ]
        },
        {
          "name": "amount",
          "display": "Amount",
          "description": "",
          "type": "decimal",
          "validations": [
            {
              "type": "presence",
              "options": {}
            },
            {
              "type": "numericality",
              "options": {
                "greater_than": 0
              }
            }
          ]
        },
        {
          "name": "max_gas",
          "display": "Max Gas",
          "description": "",
          "type": "decimal",
          "validations": []
        }
      ]
    }
  ],
  "data": {
    "delegator_address": null,
    "delegator_pubkey": null,
    "validator_address": null,
    "amount": null,
    "max_gas": null,
    "delegate_transaction": null
  },
  "protocol": "near",
  "network": "testnet",
  "created_at": "2022-09-26T15:24:43.720Z",
  "updated_at": "2022-09-26T15:24:43.720Z"
}

Submit Delegate Data

After creating a new staking flow, submit the staking account data. Collect the required inputs. Send a PUT request to /flows/[:flow_id]/next to proceed to the next step.

URL

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

Request

  • name* : create_delegate_tx
  • inputs* : object
    • delegator_address* : string The delegating address.
    • delegator_pubkey* : string The public key of the signing account.
    • validator_address* : string Address of the validator to which you want to delegate your tokens.
    • amount* : number The amount of NEAR to be delegated.
    • max_gas : string Adjust if you wish to limit the possible transaction fee.
{
  "name": "create_delegate_tx",
  "inputs": {
    "delegator_address": "slate-demo.testnet",
    "delegator_pubkey": "ed25519:5QA46X6NkNmsFdu9xWVBaLNowh9gGeF1c5r9u6NcxaLY",
    "validator_address": "01node.pool.f863973.m0",
    "amount": "25",
    "max_gas": null
  }
}

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.
  • data : object Flow & transaction data.
{
  "id": "11cbb22a-3505-4d9d-aa82-61a9d865dfdd",
  "state": "delegate_tx_signature",
  "actions": [
    {
      "name": "refresh_delegate_tx",
      "inputs": [
        {
          "name": "delegator_address",
          "display": "Delegator Address",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": "136df0c876f120f3b823754f57dee6064c18a9f9560081d3.testnet"
        },
        {
          "name": "delegator_pubkey",
          "display": "Delegator Pubkey",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": "ed25519:46c3btaWiBB2DCieDnQffBN4DixAHU69qYWqNzCBBgsQ"
        },
        {
          "name": "validator_address",
          "display": "Validator Address",
          "description": "",
          "type": "string",
          "validations": [
            {
              "type": "presence",
              "options": {}
            }
          ],
          "array": false,
          "default_value": "legends.pool.f863973.m0"
        },
        {
          "name": "amount",
          "display": "Amount",
          "description": "in NEAR",
          "type": "decimal",
          "validations": [
            {
              "type": "presence",
              "options": {}
            },
            {
              "type": "numericality",
              "options": {
                "greater_than": 0
              }
            }
          ],
          "array": false,
          "default_value": "10.0"
        },
        {
          "name": "max_gas",
          "display": "Max Gas",
          "description": "in NEAR",
          "type": "decimal",
          "validations": [
            {
              "type": "numericality",
              "options": {
                "allow_nil": true,
                "greater_than": 0
              }
            }
          ],
          "array": false,
          "default_value": null
        }
      ]
    },
    {
      "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": [
            "ed25519:46c3btaWiBB2DCieDnQffBN4DixAHU69qYWqNzCBBgsQ"
          ],
          "transaction_payload": "380000003133366466306338373666313230663362383233373534663537646565363036346331386139663935363030383164332e746573746e6574002e0297153490ddde81b8f300b1a96598bc13e5c8c2f0b61d8eaf27ff40db20b741c1d946ab690000170000006c6567656e64732e706f6f6c2e663836333937332e6d3013c8809bd8dc4670762fff3fc5988e682c51f63a60013cba9d8ae6a78722f61d0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000"
        },
        {
          "name": "signatures",
          "display": "Signatures",
          "description": "",
          "type": "array_of_signatures",
          "validations": [],
          "array": true,
          "default_value": null,
          "element_type": "signature_data",
          "signers": [
            "ed25519:46c3btaWiBB2DCieDnQffBN4DixAHU69qYWqNzCBBgsQ"
          ],
          "transaction_payload": "380000003133366466306338373666313230663362383233373534663537646565363036346331386139663935363030383164332e746573746e6574002e0297153490ddde81b8f300b1a96598bc13e5c8c2f0b61d8eaf27ff40db20b741c1d946ab690000170000006c6567656e64732e706f6f6c2e663836333937332e6d3013c8809bd8dc4670762fff3fc5988e682c51f63a60013cba9d8ae6a78722f61d0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000",
          "signing_payload": "dd74125fef57262cbe445e13cceb5073873605aa0e6019ce7502c51a3e3cd8bf",
          "inputs": {
            "input_klass": "Workflows::Signature",
            "input_instance": {
              "account_address": null,
              "signature": null
            },
            "flow": {
              "workflow_state": "delegate_tx_signature",
              "id": 3803,
              "customer_id": 40,
              "chain_id": 7,
              "data": {
                "delegator_address": "136df0c876f120f3b823754f57dee6064c18a9f9560081d3.testnet",
                "delegator_pubkey": "ed25519:46c3btaWiBB2DCieDnQffBN4DixAHU69qYWqNzCBBgsQ",
                "validator_address": "legends.pool.f863973.m0",
                "amount": "10.0",
                "max_gas": null,
                "delegate_transaction": {
                  "raw": "380000003133366466306338373666313230663362383233373534663537646565363036346331386139663935363030383164332e746573746e6574002e0297153490ddde81b8f300b1a96598bc13e5c8c2f0b61d8eaf27ff40db20b741c1d946ab690000170000006c6567656e64732e706f6f6c2e663836333937332e6d3013c8809bd8dc4670762fff3fc5988e682c51f63a60013cba9d8ae6a78722f61d0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000",
                  "signing_payload": "dd74125fef57262cbe445e13cceb5073873605aa0e6019ce7502c51a3e3cd8bf",
                  "signed": null,
                  "hash": "FuTkq5oYo9t8rUoGphpcuE1sEcJzYBU7QQbgY2Ah8L1U",
                  "status": null,
                  "error": null,
                  "signatures": null
                }
              },
              "created_at": "2023-02-24T22:48:42.104Z",
              "updated_at": "2023-02-24T22:48:53.366Z",
              "id_public": "11cbb22a-3505-4d9d-aa82-61a9d865dfdd",
              "supported_operation_id": 20
            },
            "flow_attributes": {},
            "empty_input": {
              "account_address": null,
              "signature": 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": "136df0c876f120f3b823754f57dee6064c18a9f9560081d3.testnet",
    "delegator_pubkey": "ed25519:46c3btaWiBB2DCieDnQffBN4DixAHU69qYWqNzCBBgsQ",
    "validator_address": "legends.pool.f863973.m0",
    "amount": "10.0",
    "max_gas": null,
    "delegate_transaction": {
      "raw": "380000003133366466306338373666313230663362383233373534663537646565363036346331386139663935363030383164332e746573746e6574002e0297153490ddde81b8f300b1a96598bc13e5c8c2f0b61d8eaf27ff40db20b741c1d946ab690000170000006c6567656e64732e706f6f6c2e663836333937332e6d3013c8809bd8dc4670762fff3fc5988e682c51f63a60013cba9d8ae6a78722f61d0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000",
      "signing_payload": "dd74125fef57262cbe445e13cceb5073873605aa0e6019ce7502c51a3e3cd8bf",
      "signed": null,
      "hash": "FuTkq5oYo9t8rUoGphpcuE1sEcJzYBU7QQbgY2Ah8L1U",
      "status": null,
      "error": null,
      "signatures": null
    }
  },
  "protocol": "near",
  "network": "testnet",
  "created_at": "2023-02-24T22:48:42.104Z",
  "updated_at": "2023-02-24T22:48:53.366Z"
}

Submit Signed Delegate Transaction for Broadcast

Before broadcasting the transaction, you must sign the transaction_payload you received in the previous step. After signing the transaction, send a PUT request to /flows/[:flow_id]/next with the signed payload. The Staking API will broadcast the transaction to the Ethereum network.

URL

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

Request

  • name* : string Name of the action to execute.
  • inputs* : object
    • transaction_payload* : Signed transaction payload from the previous step's response.
    • signatures : array of object The signatures array can be used instead of sending a transaction payload when the signing keys are kept in a custodial solution, such as Fireblocks. Refer to the guide Signing Transactions with the Fireblocks API for details.
{
  "name": "sign_delegate_tx",
  "inputs": {
    "transaction_payload": "12000000736c6174652d64656d6f2e746573746e657400415d57cdf21d28e35e0cfa864e895c18b4bc6a711642d38eb6762af81ec1cf3904cc1038fc5700001600000030316e6f64652e706f6f6c2e663836333937332e6d309ab9d36f31580c94fcf7eace07f4a286a6f69cdd3caef0efed5d78930df546880100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b0000000000b9340332b7f4ad14000000000000cd7538bc1db22a72cbaa19f54e9df00b9444863c74eefd5897d2ebbb7a52e7f8042d675c09d40684b7f7dd17feb73ecd09f6ae08c33e7f82450b438694f5430e"
  }
}

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.
    • delegate_tx_broadcasting : Transaction has been broadcast and is confirming.
    • delegated : Transaction has been confirmed and the delegation is active.
  • actions : array It includes the name & inputs of all next possible actions.
  • data : object Flow & transaction data.
{
  "id": "549db585-874f-4b5d-b1a2-67b7d9a3df15",
  "state": "delegate_tx_broadcasting",
  "actions": [
    {
      "name": "wait",
      "estimated_state_change_at": "2023-02-27T17:48:51.908Z",
      "inputs": []
    }
  ],
  "data": {
    "delegator_address": "0b81cc09294fc074814ad0de50f31644e5669f856105399b.testnet",
    "delegator_pubkey": "ed25519:NUbTcj78nHFFm1J8a1GFjenAnCKV32ZdBeeqem8oyLV",
    "validator_address": "legends.pool.f863973.m0",
    "amount": "10.0",
    "max_gas": null,
    "delegate_transaction": {
      "raw": "380000003062383163633039323934666330373438313461643064653530663331363434653536363966383536313035333939622e746573746e657400058065d39e25bf5038afbacc1b7312c5dc3761770626288020d783f8685058aa412e4c11c36b0000170000006c6567656e64732e706f6f6c2e663836333937332e6d3060877de2656b98d64e2cecadb55050ee8aa435e81dc657911adc65bb569bf7fb0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000",
      "signing_payload": "c9f587150ebf9aa0d8c20510a71574a094224c636a1d40e9c80e13f7d0ed04ea",
      "signed": "380000003062383163633039323934666330373438313461643064653530663331363434653536363966383536313035333939622e746573746e657400058065d39e25bf5038afbacc1b7312c5dc3761770626288020d783f8685058aa412e4c11c36b0000170000006c6567656e64732e706f6f6c2e663836333937332e6d3060877de2656b98d64e2cecadb55050ee8aa435e81dc657911adc65bb569bf7fb0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000007a3f50c131f084dc733fc56e16c888fc7f42a0e49000e8948065e1663d1f57849788b40dfbabdc1e6734d78f6fe4e7803372a251fb9c9473ca443575102b1303",
      "hash": "EbN6QPxd81V8CGViBFMtTjoqnoPV5bH34kyiV5vu9XvH",
      "status": null,
      "error": null,
      "signatures": []
    }
  },
  "protocol": "near",
  "network": "testnet",
  "created_at": "2023-02-27T17:46:45.944Z",
  "updated_at": "2023-02-27T17:47:51.535Z"
}

Get Staking Flow Status

To get the current state of the existing flow, send a GET request to /flows/[:flow_id] using the flow ID from the previous step.

URL

https://api.figment.io/flows/[:flow_id]

Request

  • None

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.
    • delegate_tx_broadcasting : Transaction has been broadcast and is confirming.
    • delegated : Transaction has been confirmed and the delegation is active.
  • actions : array It includes the name & inputs of all next possible actions.
  • data : object Flow & transaction data.
{
  "id": "549db585-874f-4b5d-b1a2-67b7d9a3df15",
  "state": "delegated",
  "actions": [],
  "data": {
    "delegator_address": "0b81cc09294fc074814ad0de50f31644e5669f856105399b.testnet",
    "delegator_pubkey": "ed25519:NUbTcj78nHFFm1J8a1GFjenAnCKV32ZdBeeqem8oyLV",
    "validator_address": "legends.pool.f863973.m0",
    "amount": "10.0",
    "max_gas": null,
    "delegate_transaction": {
      "raw": "380000003062383163633039323934666330373438313461643064653530663331363434653536363966383536313035333939622e746573746e657400058065d39e25bf5038afbacc1b7312c5dc3761770626288020d783f8685058aa412e4c11c36b0000170000006c6567656e64732e706f6f6c2e663836333937332e6d3060877de2656b98d64e2cecadb55050ee8aa435e81dc657911adc65bb569bf7fb0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000",
      "signing_payload": "c9f587150ebf9aa0d8c20510a71574a094224c636a1d40e9c80e13f7d0ed04ea",
      "signed": "380000003062383163633039323934666330373438313461643064653530663331363434653536363966383536313035333939622e746573746e657400058065d39e25bf5038afbacc1b7312c5dc3761770626288020d783f8685058aa412e4c11c36b0000170000006c6567656e64732e706f6f6c2e663836333937332e6d3060877de2656b98d64e2cecadb55050ee8aa435e81dc657911adc65bb569bf7fb0100000002110000006465706f7369745f616e645f7374616b65020000007b7d00e057eb481b00000000004a480114169545080000000000007a3f50c131f084dc733fc56e16c888fc7f42a0e49000e8948065e1663d1f57849788b40dfbabdc1e6734d78f6fe4e7803372a251fb9c9473ca443575102b1303",
      "hash": "EbN6QPxd81V8CGViBFMtTjoqnoPV5bH34kyiV5vu9XvH",
      "status": "confirmed",
      "error": null,
      "signatures": []
    }
  },
  "protocol": "near",
  "network": "testnet",
  "created_at": "2023-02-27T17:46:45.944Z",
  "updated_at": "2023-02-27T17:48:05.958Z"
}