Unbonding Babylon
The unbonding
method creates unsigned transaction for unbonding (undelegation which need to withdraw then)
unbonding(stakingTxHash, feeRate = 1)
: Unbond stake from specific staking Tx.
js
const { Babylon, signetNetwork } = require("@everstake/wallet-sdk/babylon");
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66
// create instance of Babylon class
const babylon = new Babylon(signetNetwork, keyPair.publicKey, token);
// stake tx hash which need to unbond
const stakeTxHash = '00000000000000000000000000000000000000'
// get unsigned tx
const unsignedUnbondingTx = await babylon.unbonding(stakeTxHash);
// sign tx
const signedTx = unsignedUnbondingTx.psbt.signInput(0, keyPair);
signedTx.finalizeAllInputs();
const tx = Psbt.fromHex(signedTx.toHex()).extractTransaction();
// collect data and send it to Babylon API
const stakerSignature = tx.ins[0].witness[0].toString('hex')
const unbondingTxHex = tx.toHex()
await babylon.sendUnbondingTx({
staker_signed_signature_hex: stakerSignature,
staking_tx_hash_hex: stakeTxHash,
unbonding_tx_hash_hex: tx.getId(),
unbonding_tx_hex: unbondingTxHex,
})