Skip to main content

Unstake Solana

The unstake action triggers the withdrawal process for Solana staking. The workflow initialization returns a corresponding unsigned transaction that users can sign and submit to the Solana network.

More detail on Solana can be found within our Solana protocol guide

The sample code below will guide you through generating an unsigned Solana unstaking transaction.

1. Instantiate your staking client

To start, import the necessary dependencies and instantiate your staking client.

import { StakingClient } from '@coinbase/staking-client-library-ts';
import { Workflow } from '@coinbase/staking-client-library-ts/src/gen/coinbase/staking/orchestration/v1/workflow.pb';

const client = new StakingClient();

2. Declare your unstaking variables

Add the wallet address you intend to unstake from, the Solana stake account, the amount you wish stake and the amount.

info

Solana stake accounts are automatically created when staking through the Coinbase staking API. To retrieve a users stake account please ....

Your stake amount should be defined in the native unit. We support fractional staking up to X decimal places. For example, using an amount of '1000.5' would equate to 1000.5 SOL.

const walletAddress: string = '8rMGARtkJY5QygP1mgvBFLsE9JrvXByARJiyNfcSE5Z'; // replace with your wallet address
const stakeAccount: string = '8rMGARtkJY5QygP1mgvBFLsE9JrvXByARJiyNfcSE5Z'; // can also be derived by...
const amount: string = '1000'; // replace with your amount. For solana it should be >= 0.1 SOL
const network: string = 'devnet'; // replace with your chosen network. We support 'mainnet' or 'devnet'

3. Generate an unsigned unstaking transaction

Create a call to the staking client to generate an unsigned staking transaction using the parameters you defined in step 2.

async function unstakeSolana(): Promise<void> {
if (walletAddress === '') {
throw new Error('Please set the walletAddress variable in this file');
}

let workflow: Workflow = {} as Workflow;

try {
// Create a new eth kiln stake workflow
workflow = await client.Solana.unstake(network, walletAddress, stakeAccount, amount);

console.log(JSON.stringify(workflow, null, 2));
} catch (error) {
let errorMessage = '';

if (error instanceof Error) {
errorMessage = error.message;
}
throw new Error(`Error creating workflow: ${errorMessage}`);
}
}

unstakeSolana()
.then(() => {
console.log('Done creating sol unstaking workflow');
})
.catch((error) => {
if (error instanceof Error) {
console.error('Error creating sol unstaking workflow: ', error.message);
}
});

More Examples

Refere to the examples folder within our Staking Client docs for a full list of sample code.

Was this helpful?