# Aptos

## Getting Started <a href="#getting-started" id="getting-started"></a>

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](https://wallet-sdk-api.everstake.one/swagger/#/Aptos) with detailed examples

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

**Option 2: JavaScript library**

You can install and import Wallet SDK for Javascript.

#### Step. 1: Installing the Library <a href="#step-1-installing-the-library" id="step-1-installing-the-library"></a>

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

{% tabs %}
{% tab title="npm" %}

```sh
$ npm install @everstake/wallet-sdk
```

{% endtab %}

{% tab title="yarn" %}

```sh
$ yarn add @everstake/wallet-sdk
```

{% endtab %}
{% endtabs %}

#### Step. 2: Import Wallet SDK <a href="#step-2-import-wallet-sdk" id="step-2-import-wallet-sdk"></a>

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

**Import ES6**

```typescript
// import module
import { Aptos } from '@everstake/wallet-sdk';
// or you can also use
import * as Aptos from '@everstake/wallet-sdk/aptos';
// import needed function
import { stake } from '@everstake/wallet-sdk/aptos';
```

**Import ES5**

```typescript
// import module
const { Aptos } = require("@everstake/wallet-sdk");
// or you can also use
const { stake } = require("@everstake/wallet-sdk/aptos");
```

#### Step. 3: Create Auth Token <a href="#step-3-create-auth-token" id="step-3-create-auth-token"></a>

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**

```typescript
// 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)**](https://wallet-sdk-api.everstake.one/swagger/#/Auth/post_token_create)

```typescript
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"
}'
```

## Methods <a href="#all-aptos-methods" id="all-aptos-methods"></a>

#### Assets JS library methods <a href="#actions" id="actions"></a>

* <mark style="color:yellow;">`GetAssets(chain)`</mark>: The get Assets method provides information about the delegation pool.

#### Aptos JS library methods <a href="#actions" id="actions"></a>

* <mark style="color:yellow;">`stake(token, address, amount)`</mark>: Stakes user tokens. For the initial stake, you need to stake a minimum of 11 APT. However, if you already have an active stake more than or equal to 11 APT, the minimum amount you can add is 0.1 Aptos.
* <mark style="color:yellow;">`reactivate(token, address, amount)`</mark>: Reactivates user Stake. The user can only reactivate that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to reactivate the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when unlocking just 11 APT.
* <mark style="color:yellow;">`unlock(token, address, amount)`</mark>: Unlocks user tokens. The user can only unlock more than 11 APT and must have more than or equal to 11 APT in the active stake.If a user possesses 15 APT, they are only able to unlock the entire amount. This is due to the fact that the condition specifying the remaining active stake must be equal to or greater than 11 APT is not met when unlocking just 11 APT.
* <mark style="color:yellow;">`unstake(token, address, amount)`</mark>: Unstakes user tokens. The user can only unstake that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to unstake the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when ustaking just 11 APT.
* <mark style="color:yellow;">`sendTransfer(address, recipientAddress, amount)`</mark>: Transfers user tokens. Using this method user can transfer APT from one wallet address to another.
* <mark style="color:yellow;">`getBalanceByAddress(address)`</mark>: Gets user balance.
* <mark style="color:yellow;">`getStakeBalanceByAddress(address)`</mark>: Gets user stake balance.
* <mark style="color:yellow;">`getMinAmountForStake(address)`</mark>: Gets user min amount for stake.
* <mark style="color:yellow;">`getLockupSecs()`</mark>: Get validator lockup timeout in seconds

#### Assets API methods <a href="#actions" id="actions"></a>

* <mark style="color:yellow;">`GetAssets(chain)`</mark>: The GET Assets method provides information about the delegation pool.

#### Aptos REST API methods <a href="#actions" id="actions"></a>

* <mark style="color:yellow;">`delegate(token, address, amount)`</mark>: Stakes user tokens. For the initial stake, you need to stake a minimum of 11 APT. However, if you already have an active stake more than or equal to 11 APT, the minimum amount you can add is 0.1 Aptos.
* <mark style="color:yellow;">`unlock(token, address, amount)`</mark>: Unlocks user tokens. The user can only unlock more than 11 APT and must have more than or equal to 11 APT in the active stake.If a user possesses 15 APT, they are only able to unlock the entire amount. This is due to the fact that the condition specifying the remaining active stake must be equal to or greater than 11 APT is not met when unlocking just 11 APT.
* <mark style="color:yellow;">`reactivateStake(token, address, amount)`</mark>: Reactivates user Stake. The user can only reactivate that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to reactivate the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when unlocking just 11 APT.
* <mark style="color:yellow;">`undelegate(token, address, amount)`</mark>. Unstakes user tokens. The user can only unstake that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to unstake the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when ustaking just 11 APT.
* <mark style="color:yellow;">`transfer(address, amount, recipientAddress)`</mark>: Transfers user tokens. Using this method user can transfer APT from one wallet address to another.
* <mark style="color:yellow;">`getLockupSecs()`</mark>: Gets a validator lockup expired period in seconds
* <mark style="color:yellow;">`getBalanceByAddress(address)`</mark>: Gets user balance.
* <mark style="color:yellow;">`getStakeBalanceByAddress(address)`</mark>: Gets user stake balances.
* <mark style="color:yellow;">`getMinAmountForStakeByAddress(address)`</mark>: Gets min amount to stake.

{% hint style="danger" %} <mark style="color:$info;">**WARNING**</mark>

<mark style="color:$info;">Using REST API methods and JS library, you have to sign transaction on your side:</mark> [<mark style="color:$info;">see more</mark>](https://wallet-sdk.everstake.one/guide/aptos/sign-transaction.html)
{% endhint %}

## Stake

The <mark style="color:yellow;">`stake`</mark> namespace contains method used for sending transactions on delegation. The unique method to the <mark style="color:yellow;">`stake`</mark> namespace is:

* <mark style="color:yellow;">`stake(token, address, amount)`</mark>: Stakes user tokens. For the initial stake, you need to stake a minimum of 11 APT. However, if you already have an active stake more than or equal to 11 APT, the minimum amount you can add is 0.1 Aptos.

**Stake Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// Return min amount for stake by user address
const minAmount = await Aptos.getMinAmountForStake(address);

// The amount that the user stake
const amount = 11; // must be >= minAmount

// Stake - return Raw Transaction
const txnRequest = await Aptos.stake(token, address, amount);
console.log(txnRequest); // Raw Transaction Object
```

## Unstake  <a href="#unstake-aptos" id="unstake-aptos"></a>

The <mark style="color:yellow;">`unstake`</mark> namespace contains method used for sending transactions on unstaking. The unique method to the <mark style="color:yellow;">`unstake`</mark> namespace is:

* <mark style="color:yellow;">`unstake(token, address, amount)`</mark>: Unstakes user tokens. The user can only unstake that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to unstake the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when ustaking just 11 APT.

**Unstake Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// The amount that the user unstake
const amount = 11;

// Unstake - return Raw Transaction
const txnRequest = await Aptos.unstake(token, address, amount);
console.log(txnRequest); // Raw Transaction Object
```

## Reactivate  <a href="#reactivate-stake-aptos" id="reactivate-stake-aptos"></a>

The <mark style="color:yellow;">`reactivate`</mark> namespace contains method used for sending transactions on reactivating user stake. The unique method to the <mark style="color:yellow;">`reactivate`</mark> namespace is:

* <mark style="color:yellow;">`reactivate(token, address, amount)`</mark>: Reactivates user Stake. The user can only reactivate that number of APT, which was unlocked previously. If a user possesses 15 unlocked APT, they are only able to reactivate the entire amount. This is due to the fact that the condition specifying the remaining unlocked amount must be equal to or greater than 11 APT is not met when unlocking just 11 APT.

**Reactivate Stake Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// The amount that the user reactivate
const amount = 11;

// Reactivate - return Raw Transaction
const txnRequest = await Aptos.reactivate(token, address, amount);
console.log(txnRequest); // Raw Transaction Object
```

## Unlock Stake <a href="#unlock-aptos" id="unlock-aptos"></a>

The <mark style="color:yellow;">`unlock`</mark> namespace contains method used for sending transactions on unlocking. The unique method to the <mark style="color:yellow;">`unlock`</mark> namespace is:

* <mark style="color:yellow;">`unlock(token, address, amount)`</mark>: Unlocks user tokens. The user can only unlock more than 11 APT and must have more than or equal to 11 APT in the active stake.If a user possesses 15 APT, they are only able to unlock the entire amount. This is due to the fact that the condition specifying the remaining active stake must be equal to or greater than 11 APT is not met when unlocking just 11 APT.

**Unlock state Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66

// The amount that the user unlock
const amount = 11;

// Unlock - return Raw Transaction
const txnRequest = await Aptos.unstake(token, address, amount);
console.log(txnRequest); // Raw Transaction Object
```

## Send Transfer <a href="#transfer-aptos" id="transfer-aptos"></a>

The <mark style="color:yellow;">`transfer`</mark> namespace contains method used for sending transfer. The unique method to the <mark style="color:yellow;">`transfer`</mark> namespace is:

* <mark style="color:yellow;">`sendTransfer(address, recipientAddress, amount)`</mark>: Transfers user tokens. Using this method user can transfer APT from one wallet address to another.

**Transfer Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User Public Address
const address = '0x1bae2a9343bd546e14c5e696b45be50b7d215bb627949e1e5f82470bee9bdb62';
// Recipient Address
const recipientAddress = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';

// The amount that the user want send
const amount = 10;

// Send Transfer - return Raw Transaction
const txnRequest = await Aptos.sendTransfer(address, recipientAddress, amount);
console.log(txnRequest); // Raw Transaction Object
```

## Sign Transaction

**Sign Transaction Code Example**

```typescript
try {
    // import aptos lib
    import aptos from "aptos";
    // import SDK
    import { NODE_URL, createClient, stake } from '@everstake/wallet-sdk/aptos';
    
    // Optional
    // 1. create client using aptos lib
    // Node url you can use custom or import him
    const client = new aptos.AptosClient(NODE_URL);
    // 2. or create client using func createClient
    // const client = createClient(NODE_URL);
    
    // get UserAccount using user privateKey
    const Uint8Array = aptos.HexString.ensure(privateKey).toUint8Array();
    const UserAccount = new aptos.AptosAccount(Uint8Array);
    
    // Raw Transaction
    const txnRequest = await Aptos.stake(token, address, amount);
    
    // Sign Transaction
    const signedTxn = await client.signTransaction(UserAccount, txnRequest);
    const transactionRes = await client.submitTransaction(signedTxn);
    await client.waitForTransaction(transactionRes.hash);

    return transactionRes.hash; // return hash
} catch (error) {
    throw new Error(error);
}
```

## Getting Info  <a href="#getting-info-aptos" id="getting-info-aptos"></a>

The <mark style="color:yellow;">`get`</mark> namespace contains method used for getting info. The unique method to the <mark style="color:yellow;">`get`</mark> namespace is:

* <mark style="color:yellow;">`getBalanceByAddress(address)`</mark>: Gets user balance.
* <mark style="color:yellow;">`getStakeBalanceByAddress(address)`</mark>: Gets user stake balance.
* <mark style="color:yellow;">`getMinAmountForStake(address)`</mark>: Gets user min amount for stake.
* <mark style="color:yellow;">`getLockupSecs()`</mark>: Gets a validator lockup expired period in seconds

**Get Balance By Address Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User public address.
const address = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';

// Return user balance in APT.
const getDelegationsResult = await Aptos.getBalanceByAddress(address);
console.log(getDelegationsResult); // "2.18" (Amount in APT)
```

**Get Min Stake Amount By Address Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User public address.
const address = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';

// Return min amount for stake in APT.
const getMinAmountForStakeResult = await Aptos.getMinAmountForStake(address);
console.log(getMinAmountForStakeResult); // "11" | "0.1" (Amount in APT)
```

**Get Stake Balance By Address Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

// User public address.
const address = '0xc4c25dea791fd3e2551507e9b0524565c86da1833ade5ba61eb9967ca71fc138';

// Return user stake balance in APT.
const getStakeBalanceByAddressResult = await Aptos.getStakeBalanceByAddress(address);
console.log(getStakeBalanceByAddressResult); // see the response below
```

**Response Example**

```typescript
stake_balance = {
    // after STAKE, one of `active` + `pending_active` stake
    "active": "11",
    // one of `inactive` stake FOR each past observed lockup cycle (OLC) on the stake pool
    "inactive": "0",
    // after UNLOCK, one of `pending_inactive` stake scheduled during this ongoing OLC
    "pending_inactive": "20"
};
```

**Get a validator lockup expired period. Code Example**

```typescript
// Import SDK
import { Aptos } from '@everstake/wallet-sdk';

const lockup = await Aptos.getLockupSecs(address);
console.log(lockup); // "3600" (1 hour before luckup expired)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.everstake.one/integrations/everstake-products/wallet-sdk/protocols/aptos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
