Withdrawing Babylon
There are at least two types of withdrawing:
withdrawEarlyUnbonded(stakingTxHash, feeRate = 1)
: withdraw your stake after unbondingwithdrawTimelockUnbonded(stakingTxHash, feeRate = 1)
: withdraw your stake after your stake period is expired. No need to make unbonding before
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 unsignedWithdrawalTx = await babylon.withdrawEarlyUnbonded(stakeTxHash);
// or you should use withdrawTimelockUnbonded instead of withdrawEarlyUnbonded, it depends on conditions
// sign tx
const signedTx = unsignedWithdrawalTx.psbt.signInput(0, keyPair);
signedTx.finalizeAllInputs();
const tx = Psbt.fromHex(signedTx.toHex()).extractTransaction();
// sent to network
fetch('https://mempool.space/signet/api/tx', {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: tx.toHex()
})
.then(response => response.text())
.then(txid => {
console.log('Broadcasted Transaction ID:', txid);
})
.catch(error => {
console.error('Failed to broadcast transaction:', error);
});