Unbonding Babylon
The unbonding
method creates unsigned transaction for unbonding (undelegation which need to withdraw then)
unbonding(stakingTxHash)
: Unbond stake from specific staking Tx.
js
const { Babylon, signetNetwork } = require("@everstake/wallet-sdk/babylon");
const { Psbt } = require('bitcoinjs-lib');
// Token ID.
const token = process.env.TOKEN; // 3155f389-d943-4966-8e18-f159c2a6ef66
// create instance of Babylon class
const babylon = new Babylon(signetNetwork, Buffer.from(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,
})
Unbonding using API
At first, you need use /babylon/unbonding
endpoint to create unbonding tx, then you need to sign this transaction and make a payload which need to send to another endpoint /babylon/unbonding/send
to make order for unbonding.