Cosmos Staking API
1 Stake
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/cosmos/stake' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "cosmos1kra2kneru7tsnjl4akuwapw8fmare3qjzhzkzr",
"amount": "1"
}'
Response
{
"data": "c3d3bc2d-cb70-4753-a644-829220e85932"
}
2 Unstake
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/cosmos/unstake' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "cosmos1kra2kneru7tsnjl4akuwapw8fmare3qjzhzkzr",
"amount": "1"
}'
Response
{
"data": "0835b5d6-44e3-43cb-87cb-59655deea042"
}
3 Claim Reward
Request
curl -X 'POST' \
'https://stakingapi.infstones.com/cosmos/claim' \
-H 'x-api-key: <access_token>' \
-H 'Content-Type: application/json' \
-d '{
"wallet": "cosmos1kra2kneru7tsnjl4akuwapw8fmare3qjzhzkzr"
}'
Response
{
"data": "a24f7ab9-cf01-48f8-a37e-8a0da2287ef9"
}
4 Sign Transaction
import { coins, makeCosmoshubPath } from "@cosmjs/amino"
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing"
import {
SigningStargateClient,
calculateFee,
GasPrice,
StargateClient,
} from "@cosmjs/stargate"
const mnemonic = "<your_cosmos_wallet_mnemonic>"
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic)
const gasPrice = GasPrice.fromString("0.0025uatom")
const [account] = await wallet.getAccounts()
const rpcEndpoint = "<infstones_rpc_api_endpoint>"
const client = await SigningStargateClient.connectWithSigner(
rpcEndpoint,
wallet,
{ gasPrice: gasPrice }
)
// stake or unstake raw tx
const rawTx = {
typeUrl: "<type_url>", // "/cosmos.staking.v1beta1.MsgDelegate" | "/cosmos.staking.v1beta1.MsgUndelegate"
value: {
delegatorAddress: "<delegator_address>",
validatorAddress: "<validator_address>",
amount: {
denom: "uatom",
amount: "<amount>",
},
},
}
// claim raw tx
// const rawTx = {
// typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
// value: {
// delegatorAddress: "<delegator_address>",
// validatorAddress: "<validator_address>",
// },
// }
const memo = "<action_memo>" // memo: 'stake' | 'unstake' | 'claim'
const gasEstimation = await client.simulate(account.address, [rawTx], memo)
const fee = calculateFee(Math.round(gasEstimation * 1.3), gasPrice)
const result = await client.signAndBroadcast(
account.address,
[rawTx],
fee,
memo
)
console.log("Successfully broadcasted:", result)
Updated about 18 hours ago