Getting Started

There are two ways to start staking on the Ethereum network using the Staking API:

Get an authentication token to start using Staking API.

A request example is provided using cURL.

P2P Smart Contract

1. Create Staking Request

  1. Prepareid that is an arbitrary UUID. Generate it in one of the following ways:

  2. Set up staking nodes through P2P infrastructure by sending a POST request to /api/v1/eth/staking/direct/nodes-request/create. Use https://api-test.p2p.org for testing or https://api.p2p.org for production.

    Example request:

    curl --request POST \
         --url https://api.p2p.org/api/v1/eth/staking/direct/nodes-request/create \
         --header 'accept: application/json' \
         --header 'authorization: Bearer <token>' \
         --header 'content-type: application/json' \
         --data '
    {
      "id": "3611b95c-e1b3-40c0-9086-3de0a4379943",
      "validatorsCount": 1,
      "withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      "controllerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      "feeRecipientAddress": "0x53da3c92fCCEb0CFE1764f65DDfF1564A2b15585",
      "nodesOptions": {
        "location": "any"
      }
    }
    '
    
    • id — arbitrary UUID. You can later use that UUID to check the status of the set-up operation.

    • validatorsCount — number of validators. One validator is equal to 32 ETH.

    • withdrawalAddress — withdrawal address for the validators.

    • controllerAddress — controller address for the validators.

    • feeRecipientAddress — fee recipient address.

    • nodesOptions:

      • location — node location. Currently, only any is supported.
      • relaysSet — Miner Extractable Value (MEV) relay selection.

    Example response:

    {
      "result": true
    }
    

2. Check Request Status

Check the node set-up operation status by sending a GET request to /api/v1/eth/staking/direct/nodes-request/status/{id}.

Example request:

curl --request GET \
     --url https://api.p2p.org/api/v1/eth/staking/direct/nodes-request/status/3611b95c-e1b3-40c0-9086-3de0a4379943 \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <token>'
  • id — UUID that was specified in the node set-up request.

Example response:

{
  "result": {
    "id": "3611b95c-e1b3-40c0-9086-3de0a4379943",
    "status": "ready",
    "validatorsCount": 1,
    "withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
    "controllerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
    "feeRecipientAddress": "0x53da3c92fCCEb0CFE1764f65DDfF1564A2b15585",
    "depositData": [
      {
        "pubkey": "0xac1e9969d7b87f3102549ab41558136674a7306b85b9f73cfbd7d9fdb7db85724569da3ebd4d7de9689f6ac058d7e2a3",
        "signature": "0xb656f9c771166c82a7891b930e6a920878d9736eb3f9f241753a15ea69d8e2f20a3740dfaf546c70e31bd323e14b341205d04e3227dd4cf2923644a375f6792875ac02c5f256f7a17c96b09bafcbce7e4443e1862356b1e90d78875d78e9a742",
        "depositDataRoot": "0xba013b4950b9aff0c3c19017ec5b6e0ed5b957b36f6ff03a545e5cc5605baff8"
      }
    ]
  }
}
  • id — UUID that was specified in the node set-up request.

  • status — current status of the nodes request.

  • validatorsCount — number of validators. One validator is equal to 32 ETH.

  • withdrawalAddress — withdrawal address for the validators.

  • controllerAddress — controller address for the validators.

  • feeRecipientAddress — fee recipient address.

  • depositData:

    • pubkey — validator public key.
    • signature — validator signature.
    • depositDataRoot — SHA-256 hash of the SSZ-encoded DepositData object. Used as a protection against malformed input.

3. Prepare Staking Transaction

Create a serialized transaction for depositing the stake amount and send it as a POST request to /api/v1/eth/staking/direct/tx/deposit.

Example request:

curl --request POST \
     --url https://api.p2p.org/api/v1/eth/staking/direct/tx/deposit \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <token>' \
     --header 'content-type: application/json' \
     --data '
{
  "withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
  "depositData": [
    {
      "pubkey": "0xac1e9969d7b87f3102549ab41558136674a7306b85b9f73cfbd7d9fdb7db85724569da3ebd4d7de9689f6ac058d7e2a3",
      "signature": "0xb656f9c771166c82a7891b930e6a920878d9736eb3f9f241753a15ea69d8e2f20a3740dfaf546c70e31bd323e14b341205d04e3227dd4cf2923644a375f6792875ac02c5f256f7a17c96b09bafcbce7e4443e1862356b1e90d78875d78e9a742",
      "depositDataRoot": "0xba013b4950b9aff0c3c19017ec5b6e0ed5b957b36f6ff03a545e5cc5605baff8"
    }
  ]
}
'
  • withdrawalAddress — withdrawal address for the validators.

  • depositData:

    • pubkey — validator public key.
    • signature — validator signature.
    • depositDataRoot — hash of the deposit data.

Example response:

{
   "result": {
      "serializeTx": "0x02f902d705808301674e8508530af16e830186a094681a1b3441c6bfb12f91651efd9f02c83c0702938901bc16d674ec800000b902a44f498c730000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030aa5f27070a21d79455c4a9b73c0aa4a8b1a65a1fb530d7fd8e6cd23aa16660679ac43ee4861098f6d9166aed3a4d8abb0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002001000000000000000000000028c84612d37de9209018ad96167f12169b653e9a000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060978c565cd915f4e885b4201093d1501697610eb9ee99b9b60b70434dc330e98d5b42927725304ded48483a8b8f39506d09bcb22ee18d4f6b50257946ac5ee360385308d95c0e2bc963902d42e985c29ee489aa3c989ac1561c952a6424f107a800000000000000000000000000000000000000000000000000000000000000014cb452f6e3f10ba2175c86a0284f53fcb61404b458393391abc3d5622e3e55cdc0",
      "to": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      "gasLimit": "",
      "data": "",
      "value": "",
      "chainId": "",
      "type": "",
      "maxFeePerGas": "",
      "maxPriorityFeePerGas" : ""
   }      
}
  • serializeTx — serialized unsigned transaction.
  • to — recipient address for this transaction.
  • gasLimit — maximum gas limit for this block.
  • data — transaction data.
  • value — amount this transaction is sending in Wei.
  • chainId — chain ID this transaction is authorized on, as specified by EIP-155.
  • typeEIP-2718 type of this transaction envelope.
  • maxFeePerGas — maximum price per unit of gas this transaction will pay for the combined EIP-1559 block's base fee and this transaction's priority fee in Wei.
  • maxPriorityFeePerGas — price per unit of gas in Wei, which is added to the EIP-1559 block's base fee. This added fee is used to incentivize miners to prioritize this transaction.

4. Sign and Broadcast Transaction

Use serializeTx from the previous step to sign and send the signed transaction to the Ethereum network.

By broadcasting this transaction, you are depositing the required stake amount in the Ethereum deposit smart contract by using the P2P smart contract as a proxy.

Ethereum Deposit Smart Contract

1. Create Staking Request

  1. Prepareid that is an arbitrary UUID. Generate it in one of the following ways:

  2. Set up staking nodes through P2P infrastructure by sending a POST request to /api/v1/eth/staking/direct/nodes-request/create. Use https://api-test.p2p.org for testing or https://api.p2p.org for production.

    Example request:

    curl --request POST \
         --url https://api.p2p.org/api/v1/eth/staking/direct/nodes-request/create \
         --header 'accept: application/json' \
         --header 'authorization: Bearer <token>' \
         --header 'content-type: application/json' \
         --data '
    {
      "id": "3611b95c-e1b3-40c0-9086-3de0a4379943",
      "validatorsCount": 1,
      "withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      "controllerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      "feeRecipientAddress": "0x53da3c92fCCEb0CFE1764f65DDfF1564A2b15585",
      "nodesOptions": {
        "location": "any"
      }
    }
    '
    
    • id — arbitrary UUID. You can later use that UUID to check the status of the set-up operation.

    • validatorsCount — number of validators. One validator is equal to 32 ETH.

    • withdrawalAddress — withdrawal address for the validators.

    • controllerAddress — controller address for the validators.

    • feeRecipientAddress — fee recipient address.

    • nodesOptions:

      • location — node location. Currently, only any is supported.
      • relaysSet — Miner Extractable Value (MEV) relay selection.

    Example response:

    {
      "result": true
    }
    

2. Check Request Status

Check the node set-up operation status by sending a GET request to /api/v1/eth/staking/direct/nodes-request/status/{id}.

Example request:

curl --request GET \
     --url https://api.p2p.org/api/v1/eth/staking/direct/nodes-request/status/3611b95c-e1b3-40c0-9086-3de0a4379943 \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <token>'
  • id — UUID that was specified in the node set-up request.
    Example response:
{
  "result": {
    "id": "3611b95c-e1b3-40c0-9086-3de0a4379943",
    "status": "ready",
    "validatorsCount": 1,
    "withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
    "controllerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
    "feeRecipientAddress": "0x53da3c92fCCEb0CFE1764f65DDfF1564A2b15585",
    "depositData": [
      {
        "pubkey": "0xac1e9969d7b87f3102549ab41558136674a7306b85b9f73cfbd7d9fdb7db85724569da3ebd4d7de9689f6ac058d7e2a3",
        "signature": "0xb656f9c771166c82a7891b930e6a920878d9736eb3f9f241753a15ea69d8e2f20a3740dfaf546c70e31bd323e14b341205d04e3227dd4cf2923644a375f6792875ac02c5f256f7a17c96b09bafcbce7e4443e1862356b1e90d78875d78e9a742",
        "depositDataRoot": "0xba013b4950b9aff0c3c19017ec5b6e0ed5b957b36f6ff03a545e5cc5605baff8"
      }
    ]
  }
}
  • id — UUID that was specified in the node set-up request.

  • status — current status of the nodes request.

  • validatorsCount — number of validators. One validator is equal to 32 ETH.

  • withdrawalAddress — withdrawal address for the validators.

  • controllerAddress — controller address for the validators.

  • feeRecipientAddress — fee recipient address.

  • depositData:

    • pubkey — validator public key.
    • signature — validator signature.
    • depositDataRoot — SHA-256 hash of the SSZ-encoded DepositData object. Used as a protection against malformed input.

3. Sign and Broadcast Transaction

Clients, who prefer to construct a signature themselves to send the deposit amount to the Ethereum deposit smart contract, can retrieve all the required data from step 3 within the depositData object.

Check an example of how to sign and send a transaction to the Ethereum network.

What's Next?