Documentation v1.0 has been released! Staking Guide, Protocols, Glossary, FAQ, and Support sections have been added.

Cosmos

Getting Started

You can use two different options to implement staking for Everstake validator.

Option 1: REST API

You can use REST API to call methods which are described in Swagger with detailed examples

https://wallet-sdk-api.everstake.one

Option 2: JavaScript library

You can install and import Wallet SDK for Javascript.

Step. 1: Installing the Library

Install the npm library or yarn by copying the code below.

$ npm install @everstake/wallet-sdk

Step. 2: Import Wallet SDK

After installing the app, you can import module of needed blockchain (Ethereum, Aptos, Solana, Cosmos, Polygon are available) and use the SDK:

Import ES6

// import module
import { Cosmos } from '@everstake/wallet-sdk';
// or you can also use
import * as Cosmos from '@everstake/wallet-sdk/cosmos';
// import needed function
import { delegate } from '@everstake/wallet-sdk/cosmos';

Import ES5

// import module
const { Cosmos } = require("@everstake/wallet-sdk");
// or you can also use
const { delegate } = require("@everstake/wallet-sdk/cosmos");

Step. 3: Create Auth Token

In order to access all the features of the Wallet SDK, it's necessary for you to generate an authentication token. This token will be required in all of the methods you use.

Using JS Library

// import
const { CreateToken } = require("@everstake/wallet-sdk");

// Project name
const name = 'Everstake Wallet SDK';
// wallet | Dapp | Other
const type = 'SDK';

// Create Token - return token ID
const token = await CreateToken(name, type);
console.log(token); // 3155f389-d943-4966-8e18-f159c2a6ef66

Using REST API (Swagger)

curl -X 'POST' \
  'https://wallet-sdk-api.everstake.one/token/create' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Everstake Wallet SDK",
  "type": "SDK"
}'

Stake

The delegate namespace contains method used for sending transactions on delegation. The unique method to the delegate namespace is:

  • delegate(token, address, amount, sourceID): Delegate user tokens.

Delegate Code Example

// Import SDK
import { Cosmos } from '@everstake/wallet-sdk';

// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// User wallet address.
const address = 'examplecosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhs';

// The amount that the user delegates.
const amountDelegate = 10; // min value 0.01 (ATOM)

// Your source identificator
const sourceID = '99'

// Delegate - return transaction
const delegate = await Cosmos.delegate(token, address, amountDelegate, sourceID);
console.log(delegate); // { result: { address, msg, fee, memo } }

Unstake

The undelegate namespace contains method used for sending transactions on delegation. The unique method to the undelegate namespace is:

  • undelegate(token, address, amount): Undelegate user tokens.

Undelegate Code Example

// Import SDK
import { Cosmos } from '@everstake/wallet-sdk';

// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// User wallet address.
const address = 'examplecosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhs';

// The amount that the user undelegates.
const amountUndelegate = 10; // min value 0.01 (ATOM)

// Your source identificator
const sourceID = '99'

// undelegate - return transaction
const undelegate = await Cosmos.undelegate(token, address, amountUndelegate, sourceID);
console.log(undelegate); // { result: { address, msg, fee, memo } }

Redelegate

The redelegate namespace contains method used for sending transactions on delegation. The unique method to the redelegate namespace is:

  • redelegate(token, address, amount, validatorSrcAddress): Redelegate user tokens.

Redelegate Code Example

// Import SDK
import { Cosmos } from '@everstake/wallet-sdk';

// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// Optional: You can get all user delegations.
// User wallet address.
const address = 'examplecosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhs';
// Get all user delegations.
const getDelegations = await Cosmos.getDelegations(address);

// The amount that the user redelegates.
const amountRedelegate = getDelegations.result[0].balance.amount || 10; 
// min value 0.01 (ATOM)

// Validator Address from Redelegation.
const validatorSrcAddress = 
    getDelegations.result[0].delegation.validator_address 
    || 'cosmosvaloper1tflk30mq5vgqjdly92kkhhq3raev2hnz6eete3';

// Your source identificator
const sourceID = '99'

// redelegate - return transaction hash
const redelegate = await Cosmos.redelegate(
    token,
    address,
    amountRedelegate,
    validatorSrcAddress,
    sourceID
);
console.log(redelegate); // { result: { address, msg, fee, memo } }

Withdraw Rewards

The withdrawRewards namespace contains method used for sending transactions on delegation. The unique method to the withdrawRewards namespace is:

  • withdrawRewards(address): Withdraw user rewards.

Withdraw Rewards Code Example

// Import SDK
import { Cosmos } from '@everstake/wallet-sdk';

// User wallet address.
const address = 'examplecosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhs';

// Your source identificator
const sourceID = '99'

// reward - return transaction
const reward = await Cosmos.withdrawRewards(address, sourceID);
console.log(reward); // { result: { address, msg, fee, memo } }

Getting Info

You can use getDelegations method to get all user delegations to use them for redelegate functionality.

The get namespace contains method used for getting info. The unique method to the get namespace is:

  • getDelegations(address): Gets all user delegation.

Getting Info Code Example

// Import SDK
import { Cosmos } from '@everstake/wallet-sdk';

// User wallet address.
const address = 'examplecosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhs';

// Get all user delegation.
const getDelegationsResult = await Cosmos.getDelegations(address);
console.log(getDelegationsResult); // see the response below

Response Example

getDelegationsResult = {
  "result": [
    {
      "delegation": {
        "delegator_address": "cosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhs6ujz05e",
        "validator_address": "cosmosvaloper1ptyzewnns2kn37ewtmv6ppsvhdnmeapvtfc9y5",
        "shares": "1000.000000000000000000"
      },
      "balance": {
        "denom": "uatom",
        "amount": "1000"
      },
      "operator_address": "cosmosvaloper1ptyzewnns2kn37ewtmv6ppsvhdnmeapvtfc9y5",
      "consensus_pubkey": {
        "type": "tendermint/PubKeyEd25519",
        "value": "XiGz/D6eg3KdjaFB0uYIJwkOTW5xZcFRxJmHcQYB3zg="
      },
      "status": 3,
      "tokens": "513203840253",
      "delegator_shares": "513203840253.000000000000000000",
      "description": {
        "moniker": "WeStaking",
        "identity": "DA9C5AD3E308E426",
        "website": "https://www.westaking.io",
        "details": "Delegate your atom to us for the staking rewards. We will do our best as secure and stable validator."
      },
      "unbonding_time": "2019-09-07T12:24:58.270714195Z",
      "commission": {
        "commission_rates": {
          "rate": "0.030000000000000000",
          "max_rate": "0.200000000000000000",
          "max_change_rate": "0.010000000000000000"
        },
        "update_time": "2020-03-29T00:37:22.163935678Z"
      },
      "min_self_delegation": "1"
    },
    {
      "delegation": {
        "delegator_address": "cosmos1hgmhc4hajlh8u47wmmls6ze4yrfekhsexample",
        "validator_address": "cosmosvaloper1tflk30mq5vgqjdly92kkhhq3raev2hnz6eete3",
        "shares": "2000.000000000000000000"
      },
      "balance": {
        "denom": "uatom",
        "amount": "2000"
      },
      "operator_address": "cosmosvaloper1tflk30mq5vgqjdly92kkhhq3raev2hnz6eete3",
      "consensus_pubkey": {
        "type": "tendermint/PubKeyEd25519",
        "value": "dhhD3I5QbtC870Il4IzML5Q2AwVDiSn9/HJ9w09Rgdg="
      },
      "status": 3,
      "tokens": "7087394678764",
      "delegator_shares": "7087394678764.000000000000000000",
      "description": {
        "moniker": "Everstake",
        "identity": "EF5AC70C00BECEDC",
        "website": "https://everstake.one",
        "details": "Reliable and experienced staking service provider from Ukraine. Visit our website for more details."
      },
      "unbonding_time": "2019-12-07T19:10:59.878559804Z",
      "commission": {
        "commission_rates": {
          "rate": "0.060000000000000000",
          "max_rate": "0.200000000000000000",
          "max_change_rate": "0.010000000000000000"
        },
        "update_time": "2022-12-31T22:25:10.09405574Z"
      },
      "min_self_delegation": "1"
    }
  ]
}

Getting Undelegation Info Code Example

You can use getUndelegations method to get all user undelegations.

  • getUndelegations(address): Gets all user undelegations.

// Import SDK
import { Cosmos } from '@everstake/wallet-sdk';

// User wallet address.
const address = 'cosmos176f4pukjdnsjmvwsngxa6re8r50rkuf7dya90m';

// Get all user delegation.
const getUndelegationsResult = await Cosmos.getUndelegations(address);
console.log(getUndelegationsResult); // see the response below

Response Example

getDelegationsResult = {
    "result":[
        {
            "delegator_address":"cosmos176f4pukjdnsjmvwsngxa6re8r50rkuf7dya90m",
            "validator_address":"cosmosvaloper1tflk30mq5vgqjdly92kkhhq3raev2hnz6eete3",
            "entries":[
                {
                    "creation_height":"22341651",
                    "completion_time":"2024-10-16T15:18:43.146385254Z",
                    "initial_balance":"100000",
                    "balance":"100000",
                    "unbonding_id":"882090",
                    "unbonding_on_hold_ref_count":"0"
                }
            ]
        },
        {
            "delegator_address":"cosmos176f4pukjdnsjmvwsngxa6re8r50rkuf7dya90m",
            "validator_address":"cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn",
            "entries":[
                {
                    "creation_height":"22366902",
                    "completion_time":"2024-10-18T08:47:50.123024310Z",
                    "initial_balance":"10000",
                    "balance":"10000",
                    "unbonding_id":"884765",
                    "unbonding_on_hold_ref_count":"0"
                }
            ]
        }
    ]
}