Getting Started
To start staking on the Ethereum network using the Staking API:
- Create Staking Request: set up nodes for staking using P2P infrastructure.
- Check Request Status: check the status of the node set-up operation.
- Prepare Staking Transaction: construct a serialized transaction to deposit the stake amount with a smart contract.
Get an authentication token to start using Staking API.
Request examples are provided using cURL.
1. Create Staking Request
-
Prepare
id
that is an arbitrary UUID. Generate it in one of the following ways: -
Set up staking nodes through the P2P infrastructure by sending a POST request to /api/v1/eth/staking/direct/nodes-request/create. Use https://api-test-holesky.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", "type": "REGULAR", "validatorsCount": 1, "withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17", "eigenPodOwnerAddress": "", "controllerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17", "feeRecipientAddress": "0x53da3c92fCCEb0CFE1764f65DDfF1564A2b15585", "nodesOptions": { "location": "any", "relaysSet": "" } } '
id
— arbitrary UUID. You can later use that UUID to check the status of the set-up operation.type
— staking operation type:REGULAR
— default value for native staking transactions. Set theREGULAR
operation type.RESTAKING
— value that is used to initiate a restaking operation with the EigenPod address.
validatorsCount
— number of validators. One validator is equal to 32 ETH.withdrawalAddress
— withdrawal address for the validators.eigenPodOwnerAddress
— owner of the EigenPod address. Used in the restaking flow.feeRecipientAddress
— fee recipient address.controllerAddress
— controller address for the validators.nodesOptions
:location
— node location. Currently, onlyany
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",
"type": "REGULAR",
"status": "ready",
"validatorsCount": 1,
"withdrawalAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
"eigenPodAddress": "null",
"eigenPodOwnerAddress": "null",
"controllerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
"feeRecipientAddress": "0x53da3c92fCCEb0CFE1764f65DDfF1564A2b15585",
"depositData": [
{
"pubkey": "0xac1e9969d7b87f3102549ab41558136674a7306b85b9f73cfbd7d9fdb7db85724569da3ebd4d7de9689f6ac058d7e2a3",
"signature": "0xb656f9c771166c82a7891b930e6a920878d9736eb3f9f241753a15ea69d8e2f20a3740dfaf546c70e31bd323e14b341205d04e3227dd4cf2923644a375f6792875ac02c5f256f7a17c96b09bafcbce7e4443e1862356b1e90d78875d78e9a742",
"depositDataRoot": "0xba013b4950b9aff0c3c19017ec5b6e0ed5b957b36f6ff03a545e5cc5605baff8",
"withdrawalCredentials": "0100000000000000000000005cef11327af4104ba0f8a82fbb8628caee7cb1e3",
"amount": "32000000000",
"depositMessageRoot": "6a572503239cd1f11998af7901c0947fe36eb8efec080f22598d607d3938c1a8",
"forkVersion": "00001020",
"eth2NetworkName": "goerli",
"depositCliVersion": "2.3.0"
}
],
"createdAt": "2023-08-24T08:14:50.455Z"
},
"error": {}
}
-
id
— UUID that was specified in the node set-up request. -
status
— current status of the nodes request:init
— node request was created.processing
— node request is in progress.ready
— backend has the deposit data for the node request.cancel
— something went wrong, and the deposit data was not created.
-
validatorsCount
— number of validators. One validator is equal to 32 ETH. -
withdrawalAddress
— withdrawal address for the validators. -
eigenPodAddress
— EigenPod address that is set tonull
by default. Used in the restaking flow. -
eigenPodOwnerAddress
— owner of the EigenPod address. -
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-encodeddepositData
object. Used as a protection against malformed input.withdrawalCredentials
— withdrawal address credentials, passed in the expected format by the Ethereum deposit smart contract.amount
— amount of ETH, denominated in Gwei, that is being deposited.depositMessageRoot
— cryptographic hash of the Merkle tree’s root, ensuring the integrity and authenticity of the deposit data.forkVersion
— version of the network fork that the deposit is intended for. It helps in aligning the deposit with a specific version of the protocol.eth2NetworkName
— name of the Ethereum 2.0 network where the deposit is made.depositCliVersion
— version of the deposit command-line interface (CLI) tool that was used to generate the deposit data.
-
createdAt
— timestamp of the transaction in the ISO 8601 format.
3. Prepare Staking Transaction
There are two ways to prepare a staking transaction using the Staking API:
- Interact directly with the Ethereum Deposit Smart Contract.
- Utilize the P2P smart contract.
Ethereum Deposit Smart Contract
This option can be preferable for clients, who have a lot of engineering resources available and don't want their infrastructure to have an extra dependency. In this case:
- Retrieve all the required data from the step 2 within the
depositData
object and prepare the staking transaction yourselves. - Construct a signature and send the deposit amount to the Ethereum deposit smart contract. Check an example of how to sign and send a transaction to the Ethereum network.
P2P Smart Contract
-
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:
{ "error": null, "result": { "serializeTx": "0x02f902d9824268808402718e18847c8ca34c830186a09494edf7e950fa01baa44a8690cac64264cdb7ca7c8901bc16d674ec800000b902a44f498c730000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000308c0bbe942f40bf50895da668c95fb1feede465ab175d5f93e00a8c33d146584f7f4ee4f963d317844be5d552135b595a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020010000000000000000000000338ef19fa2ec0fc4d1277b1307a613fa1fbbc0cb000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060ac5b5e49f647d6107d71a08e255bfead1c5c42375f50e5301ffa4f5e36a8ccf159e3a594069375aef5dd2a23718634950f99947f24e67cc7a84c9f805849a7b0ac5ca732e63cca1f876dbac7e0efc8000a0f19e04bf5df80c7131d30cf45e8f3000000000000000000000000000000000000000000000000000000000000000101a591baee083825d59d36f06b4d0fbd55688ed81b337819a2bf145cb8a2a022c0", "to": "0x94EDf7e950fA01bAa44a8690cAC64264cdB7cA7c", "gasLimit": "100000", "data": "0x4f498c730000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000308c0bbe942f40bf50895da668c95fb1feede465ab175d5f93e00a8c33d146584f7f4ee4f963d317844be5d552135b595a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020010000000000000000000000338ef19fa2ec0fc4d1277b1307a613fa1fbbc0cb000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060ac5b5e49f647d6107d71a08e255bfead1c5c42375f50e5301ffa4f5e36a8ccf159e3a594069375aef5dd2a23718634950f99947f24e67cc7a84c9f805849a7b0ac5ca732e63cca1f876dbac7e0efc8000a0f19e04bf5df80c7131d30cf45e8f3000000000000000000000000000000000000000000000000000000000000000101a591baee083825d59d36f06b4d0fbd55688ed81b337819a2bf145cb8a2a022", "value": "32000000000000000000", "chainId": 1, "type": 2, "maxFeePerGas": "2089591628", "maxPriorityFeePerGas": "40996376" } }
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.type
— EIP-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.
-
-
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.
What's Next?
- Withdrawal.
- Staking API reference.
Updated 6 days ago