Getting Started
Staking in the Cosmos network using the Staking API consists of several main steps:
- Create a stake transaction.
- Sign and send the transaction to the network.
Get an authentication token to start using Staking API.
A request example is provided using cURL.
1. Create Stake Transaction
Send a POST request to /api/v1/cosmos/{network}/staking/stake.
Example request (for cosmoshub
network):
curl --request POST \
--url https://api-test.p2p.org/api/v1/cosmos/cosmoshub-4/staking/stake \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"stashAccountAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
"memo": "This is your memo message",
"amount": 0.00420
}'
stashAccountAddress
— delegator stash account address which keeps tokens.memo
— arbitrary text data to add to the transactions.amount
— amount of tokens to stake in ATOM.
Example response:
{
"error": null,
"result": {
"amount": 0.0042,
"currency": "atom",
"validatorAddress": "cosmosvaloper17lgg03ze9x6xka02fs0hhw4ad4wwg05heqr2y8",
"stashAccountAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
"rewardDestinationAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
"transactionData": {
"messages": [
{
"typeUrl": "/cosmos.staking.v1beta1.MsgDelegate",
"value": {
"delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
"validatorAddress": "cosmosvaloper17lgg03ze9x6xka02fs0hhw4ad4wwg05heqr2y8",
"amount": {
"denom": "uatom",
"amount": "4200"
}
}
}
],
"fee": {
"amount": [
{
"amount": "5953",
"denom": "uatom"
}
],
"gas": "238098"
},
"memo": "The message",
"encodedBody": "0a9b010a232f636f736d6f732e7374616b696e672e763162657461312e4d736744656c656761746512740a2d636f736d6f733179397765666d6c706d30646a6b74387373656576656b653068747466756b67326136306730721234636f736d6f7376616c6f70657231376c676730337a65397836786b613032667330686877346164347777673035686571723279381a0d0a057561746f6d120434323030120b546865206d657373616765",
"encodedAuthInfo": "0a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b0c7ac278e1941ac0b65d6bd45d541cae58aa584058fbbd822311b8718708c0e12040a020801182312130a0d0a057561746f6d1204353935331092c40e"
},
"createdAt": "2023-11-02T11:21:40.810Z"
}
}
amount
— amount of tokens to stake.currency
— currency of tokens:atom
— ATOM, Cosmos native staking token.uatom
— 1 ATOM = 10^-6 UATOM,matom
— 1 ATOM = 10^-3 MATOM.
validatorAddress
— validator address to which tokens are delegated.stashAccountAddress
— delegator stash account address which keeps tokens.rewardDestinationAddress
— reward destination account address.createdAt
— timestamp of the transaction in the ISO 8601 format.
transactionData
is the list of data fields to be used to construct the staking transactions:
messages
:typeUrl
— Cosmos network operation type.delegatorAddress
— delegator address.validatorAddress
— validator address.amount
— amount of tokens to stake.currency
— currency of tokens.
fee
— fee charged for the transaction.amount
— amount of tokens.denom
— currency of tokens:atom
,uatom
, ormatom
.gas
— amount of gas spent for the transaction.
memo
— arbitrary text data to add to the transactions.encodedBody
— processable transaction data encoded in the hexadecimal format.encodedAuthInfo
— authorization data, including fee, encoded in the hexadecimal format.
2. Sign and Send Transaction
Use transactionData
to sign and send the signed transaction to the Cosmos network.
To check the transaction status, send a GET request to /api/v1/cosmos/{network}/transaction/status/{transactionHash}.
Example request (for cosmoshub
network):
curl --request GET \
--url https://api-test.p2p.org/api/v1/cosmos/cosmoshub-4/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47 \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json'
transactionHash
— hash of the transaction.
Example response:
{
"error": null,
"result": {
"status": "success",
"blockId": 18575267,
"fee": 0.005952,
"gas": {
"used": 202947,
"wanted": 238047
},
"transactionHash": "ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47"
}
}
status
— transaction status:success
,failed
.blockId
— unique identifier of the block in which the transaction has been included.fee
— total fee in ATOM charged for processing the transaction.gas
— computational effort required to execute the transaction, measured in gas units.used
— amount of gas spent for the transaction.wanted
— maximum gas limit that the transaction initiator was willing to consume for the transaction.
transactionHash
— hash of the transaction.
What's Next?
- Sign and Send Transaction.
- Withdrawal.
- Staking API reference.
Updated 9 months ago