Skip to content
On this page

Withdraw Rewards

The withdrawRewardsTx 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);