How to Transfer sBTC on Stacks Paying Fees with sBTC

Introduction
Project repository on GitHub: Bolt Protocol
Overview of Stacks and the Importance of sBTC
Stacks is a blockchain network that brings smart contracts to Bitcoin, enabling decentralized applications (dApps) secured by Bitcoin’s robust security. sBTC (Stacks Bitcoin) is a token that represents Bitcoin on the Stacks blockchain, making it easier to use Bitcoin within the Stacks ecosystem.
Benefits of Utilizing sBTC for Transaction Fees
Traditionally, Stacks users must hold STX tokens to pay for transaction fees, creating friction for those primarily holding Bitcoin. By using sBTC for transaction fees, users can:
Avoid acquiring additional tokens (STX).
Simplify the transaction experience by using a single token (sBTC).
Facilitate broader adoption of Bitcoin-backed transactions.
Introduction to Bolt Protocol
Bolt Protocol is designed to significantly enhance user experience on the Stacks blockchain by allowing users to pay transaction fees directly in sBTC and enabling instant transfers between Bolt-enabled wallets.
Bolt Protocol solves two main pain points:
Pay transaction fees with sBTC: Eliminates the need to hold STX tokens.
Instant transfers: Provides immediate transaction confirmations between Bolt Protocol wallets.
Using Bolt Protocol Implementation
Mainnet: https://boltproto.org/
Testnet: https://test.boltproto.org/
If you're a user wanting to transfer sBTC with Bolt Protocol, simply visit the above links. If you're a developer integrating this functionality into your wallet or dApp, follow the tutorial below.
Tutorial: Integrating sBTC Transfers with Bolt Protocol
Prerequisites
Basic understanding of Stacks blockchain and smart contracts
Development environment configured for interacting with Stacks
Access to the Bolt Protocol smart contract (mainnet or testnet)
Smart Contract Addresses
Mainnet: SP3QZNX3CGT6V7PE1PBK17FCRK1TP1AT02ZHQCMVJ.boltproto-sbtc-v2
Testnet: ST3QZNX3CGT6V7PE1PBK17FCRK1TP1AT02W1N0YJF.boltproto-sbtc-rc-2-0-0
Step-by-Step Guide
Step 1: Prepare Transaction Parameters
To transfer sBTC from one Stacks wallet to another using the Bolt Protocol, you'll use the function transfer-stacks-to-stacks
.
Parameters:
(transfer-stacks-to-stacks
(amount uint)
(recipient principal)
(memo (optional (buff 34)))
(fee uint))
amount: Amount of sBTC to transfer (in satoshis).
recipient: Stacks wallet address of the recipient.
memo (optional): Additional data or message (up to 34 bytes).
fee: Transaction fee amount in sBTC.
Step 2: Estimate the Transaction Fee
To calculate the sBTC transaction fee:
Obtain estimated fee in microSTX using standard Stacks estimation tools.
Fetch the current fee rate:
GET https://boltproto.org/api/v1/transaction/sbtc-token/fee-rate
Example response:
{
"feeRate": 200
}
- Calculate sBTC fee:
sBTC fee (in sats) = estimated fee in microSTX / feeRate
Example calculation:
Estimated fee =
4,000
microSTXFee rate =
200
Calculated sBTC fee =
4,000 / 200 = 20 sats
Step 3: Serialize and Submit Transaction
Create and serialize the transaction based on the parameters.
Submit via Bolt API:
POST https://boltproto.org/api/v1/transaction/sbtc-token
Request body:
{
"serializedTx": "<serialized_transaction_data>"
}
Response:
{
"txid": "<transaction_id>"
}
Step 4: Verify Transaction
Confirm the transaction submission by checking the transaction history:
GET https://boltproto.org/api/v1/wallet/<address>/sbtc-token/transactions
Implementation Example using stacks.js
Install Dependencies
npm install @stacks/network @stacks/common @stacks/transactions
Complete Example
import { StacksTestnet } from "@stacks/network";
import { bytesToHex } from "@stacks/common";
import {
uintCV,
noneCV,
makeContractCall,
PostConditionMode,
} from "@stacks/transactions";
async function transferStacksToStacks() {
const amount = 100000000; // 1 sBTC in satoshis
const fee = 10; // sBTC fee in satoshis
const network = new StacksTestnet();
const txOptions = {
contractAddress: "ST3QZNX3CGT6V7PE1PBK17FCRK1TP1AT02W1N0YJF",
contractName: "boltproto-sbtc-rc-2-0-0",
functionName: "transfer-stacks-to-stacks",
functionArgs: [
uintCV(amount),
"<recipient-address>",
noneCV(),
uintCV(fee),
],
senderKey: "<sender-private-key>",
sponsored: true,
network,
postConditionMode: PostConditionMode.Deny,
postConditions: [],
};
const transaction = await makeContractCall(txOptions);
const serializedTx = bytesToHex(transaction.serialize());
const response = await fetch('https://boltproto.org/api/v1/transaction/sbtc-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ serializedTx })
});
const data = await response.json();
console.log('Transaction submitted:', data.txid);
return data;
}
Conclusion
You've successfully integrated Bolt Protocol for transferring sBTC between Stacks wallets, paying transaction fees directly in sBTC, simplifying user experience, and enhancing transaction efficiency.
For further assistance or inquiries:
- Twitter: @boltprotobtc
Happy building!
Subscribe to my newsletter
Read articles from Ronoel Botelho directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
