> For the complete documentation index, see [llms.txt](https://docs.everstake.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.everstake.com/integrations/everstake-products/wallet-sdk/protocols/cardano.md).

# Cardano

Learn how to integrate Cardano staking into your app using Everstake Wallet SDK.

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

The Cardano wallet SDK library provides class with batch of methods that helps to manage user's stake.

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

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

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

{% endtab %}

{% tab title="yarn" %}

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

{% endtab %}
{% endtabs %}

This code example how to make Cardano instance. The base account should be in correct format - bech32. To create instance also need to get a blockFrostProjectID. More details can be found here <https://blockfrost.io/> . Be careful when use network. (preview and preprod are testnets). All code examples use meshjs library, but it's not required to reuse.

```typescript
import {CardanoWeb3} from "cardano-web3-js"
import {Cardano} from "@everstake/wallet-sdk-cardano";

import {Cardano} from "@everstake/wallet-sdk-cardano";
import {BlockfrostProvider, MeshWallet} from "@meshsdk/core";

const blockFrostID = '...';
const mnemonic = '...';
const network = 'preview';
const networkID = 0;

const cardano = new Cardano(network, paymentWallet.addresses.baseAddressBech32!, blockFrostID);
await cardano.init();
```

<mark style="color:yellow;">`cardano.init()`</mark> must be called. it will not work without that.

(Optionally) Methods <mark style="color:yellow;">`stake()`</mark>, <mark style="color:yellow;">`registerTx()`</mark> and <mark style="color:yellow;">`delegateTx()`</mark> required information about pool. It automatically calls\ <mark style="color:yellow;">`selectPool()`</mark> methods, that is a bit slowly. But it can be preloaded if <mark style="color:yellow;">`selectPool()`</mark> will be lazy loaded before delegations methods to save some time.

```typescript
await cardano.selectPool(); // preloaded
const tx = await registerTx() // selectPool() will skipped
```

## Stake <a href="#register-and-delegate" id="register-and-delegate"></a>

The <mark style="color:yellow;">`stakeTx`</mark> method creates unsigned transaction for register stake account, delegate to staking pool and vote for DRep.

```typescript
import {Cardano} from "@everstake/wallet-sdk-cardano";
import {BlockfrostProvider, MeshWallet} from "@meshsdk/core";

const blockFrostID = '...';
const mnemonic = '...';
const network = 'preview';
const networkID = 0;

const provider = new BlockfrostProvider(blockFrostID);
const paymentWallet = new MeshWallet({
    networkId: networkID,
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: mnemonic.split(' ')
    },
    accountType: 'payment'
});
await paymentWallet.init();
const stakeWallet = new MeshWallet({
    networkId: networkID,
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: mnemonic.split(' ')
    },
    accountType: 'stake'
});
await stakeWallet.init();

const cardano = new Cardano(network, paymentWallet.addresses.baseAddressBech32!, blockFrostID);
await cardano.init();

const tx = await cardano.delegateTx();
let signedTx = await paymentWallet.signTx(tx, true);
signedTx = await stakeWallet.signTx(signedTx, true);
const txHash = await paymentWallet.submitTx(signedTx);
console.log('txHash', txHash);
```

Also, an alternative option it can be called as separate methods.

```typescript
const delegationTx = await cardano.registerTx();
```

```typescript
const delegationTx = await cardano.delegateTx();
```

```typescript
const voteTx = await cardano.voteDRep();
```

## Unstake <a href="#deregistration" id="deregistration"></a>

The <mark style="color:yellow;">`deregisterTx`</mark> method creates unsigned transaction for deregistration stake. This method returns pledge (2 ADA) + stake (delegation) + rewards. So no need to claim rewards additionally.

```typescript
import {Cardano} from "@everstake/wallet-sdk-cardano";
import {BlockfrostProvider, MeshWallet} from "@meshsdk/core";

const blockFrostID = '...';
const mnemonic = '...';
const network = 'preview';
const networkID = 0;

const provider = new BlockfrostProvider(blockFrostID);
const paymentWallet = new MeshWallet({
    networkId: networkID,
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: mnemonic.split(' ')
    },
    accountType: 'payment'
});
await paymentWallet.init();
const stakeWallet = new MeshWallet({
    networkId: networkID,
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: mnemonic.split(' ')
    },
    accountType: 'stake'
});
await stakeWallet.init();

const cardano = new Cardano(network, paymentWallet.addresses.baseAddressBech32!, blockFrostID);
await cardano.init();

const tx = await cardano.deregisterTx();
let signedTx = await paymentWallet.signTx(tx, true);
signedTx = await stakeWallet.signTx(signedTx, true);
const txHash = await paymentWallet.submitTx(signedTx);
console.log('txHash', txHash);
```

## Get Info <a href="#get-info-methods" id="get-info-methods"></a>

Method <mark style="color:yellow;">`getStakeInfo`</mark> shows information about current stake. undefined value means that account is not registered.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.getStakeInfo());
```

Method <mark style="color:yellow;">`getDelegations`</mark> shows list of delegations of current account.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.getDelegations());
```

Method <mark style="color:yellow;">`getStakeActivation`</mark> shows more information about delegation status and time to active stake.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.getStakeActivation());
```

Method <mark style="color:yellow;">`getRewardHistory`</mark> shows users rewards history per epochs.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.getRewardHistory());
```

Method <mark style="color:yellow;">`getPoolsInfos`</mark> returns info about specified pools.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.getPoolsInfos(['pool...']));
```

Method <mark style="color:yellow;">`getPoolIDs`</mark> returns list of internal pools.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.getPoolIDs());
```

Method <mark style="color:yellow;">`isInternalPoolDelegation`</mark> returns boolean value that shows is current pool delegation is to internal pool.

```typescript
const cardano = new Cardano('preview', baseAddress, blockForstProjectID);
console.log(await cardano.isInternalPoolDelegation());
```

## Withdraw Rewards <a href="#withdraw-rewards" id="withdraw-rewards"></a>

The <mark style="color:yellow;">`withdrawRewardsTx`</mark> method creates unsigned transaction for withdraw rewards. Cardano has auto compound strategy, so it means no need claim rewards to increase APR. But if rewards should be spent need to call withdraw or deregister method.

```typescript
import {Cardano} from "@everstake/wallet-sdk-cardano";
import {BlockfrostProvider, MeshWallet} from "@meshsdk/core";

const blockFrostID = '...';
const mnemonic = '...';
const network = 'preview';
const networkID = 0;

const provider = new BlockfrostProvider(blockFrostID);
const paymentWallet = new MeshWallet({
    networkId: networkID,
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: mnemonic.split(' ')
    },
    accountType: 'payment'
});
await paymentWallet.init();
const stakeWallet = new MeshWallet({
    networkId: networkID,
    fetcher: provider,
    submitter: provider,
    key: {
        type: 'mnemonic',
        words: mnemonic.split(' ')
    },
    accountType: 'stake'
});
await stakeWallet.init();

const cardano = new Cardano(network, paymentWallet.addresses.baseAddressBech32!, blockFrostID);
await cardano.init();

const tx = await cardano.withdrawRewardsTx();
let signedTx = await paymentWallet.signTx(tx, true);
signedTx = await stakeWallet.signTx(signedTx, true);
const txHash = await paymentWallet.submitTx(signedTx);
console.log('txHash', txHash);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.everstake.com/integrations/everstake-products/wallet-sdk/protocols/cardano.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
