Stake Babylon
The stake
method creates unsigned transaction for stake/delegation
stake(amount, feeRate = 1)
: Stake bitcoin stats from and for specific address. Min. stake is 0.0005 BTC
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);
// amount of stake (sats)
const amount = 50000
// get unsigned stake tx
const unsignedStakeTx = await babylon.stake(amount);
// sign tx
const tweakedChildNode = keyPair.tweak(
crypto.taggedHash('TapTweak', keyPair.publicKey.slice(1, 33)),
);
const signedTx = unsignedStakeTx.psbt.signInput(0, tweakedChildNode);
signedTx.finalizeAllInputs()
// extract and sent to network
const stakingTx = Psbt.fromHex(signedTx.toHex()).extractTransaction();
fetch('https://mempool.space/signet/api/tx', {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: stakingTx.toHex()
})
.then(response => response.text())
.then(txid => {
console.log('Broadcasted Transaction ID:', txid);
})
.catch(error => {
console.error('Failed to broadcast transaction:', error);
});