Skip to content
On this page

Register and Delegate

The stakeTx 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();