A simple, open-source API to help you create and send Bitcoin payments using PSBTs (Partially Signed Bitcoin Transactions). This project is designed for both beginners and advanced users who want to automate or scale Bitcoin payments for orders, e-commerce, or any use case.
- Create PSBTs for Bitcoin transactions
- Configurable fees (flat or fee rate)
- Bulk and single transaction support
- Multi-output PSBTs
- Easy to run locally or in production
- Secure by design (no private keys handled)
git clone https://github.com/yourusername/TSS_SendBitcoin.git
cd TSS_SendBitcoinCreate a virtual environment (recommended):
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root (or set them in your shell):
# .env
INDEXER_API_KEY="your_api_key" # Only needed if you use inscriptionId lookups
INDEXER_BASE="https://open-api-fractal.unisat.io/v1/indexer/inscription/info/"
MIN_UTXO_VALUE="330"
DEFAULT_FLAT_FEE="200"
SKIP_INSCRIPTIONS="false"
SKIP_546_UTXOS="false"
PORT="8000"python3 app.pyThe server will start at http://localhost:8000 by default.
curl -X POST http://localhost:8000/create_psbt \
-H 'Content-Type: application/json' \
-d '{
"utxos": [{"txid":"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef","vout":0,"value":10000,"scriptPubKey":"0014abcdef1234567890abcdef1234567890abcdef12"}],
"outputs": [{"address":"bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh","amount":9000}],
"fee":200
}'curl -X POST http://localhost:8000/create_psbt \
-H 'Content-Type: application/json' \
-d '{
"utxos": [{"txid":"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef","vout":0,"value":10000,"scriptPubKey":"0014abcdef1234567890abcdef1234567890abcdef12"}],
"outputs": [
{"address":"bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh","amount":5000},
{"address":"bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh","amount":3000}
],
"fee":200
}'Prepare a file (e.g. bulk_requests.json) with multiple requests (see examples/bulk_requests.json):
[
{ "utxos": [...], "outputs": [...], "fee": 200 },
{ "utxos": [...], "outputs": [...], "fee_rate": 1.5 }
]Then loop through them:
cat bulk_requests.json | jq -c '.[]' | while read req; do
curl -X POST http://localhost:8000/create_psbt \
-H 'Content-Type: application/json' \
-d "$req"
done- Open Postman
- Create a new POST request to
http://localhost:8000/create_psbt - Set body to
rawandJSON, then paste your request data - Click Send and view the response
python3 -m pytest tests/All tests should pass if your setup is correct.
- utxos: List of UTXOs to spend (each with
txid,vout,value/satoshi,scriptPubKey) - outputs: List of outputs (each with
address,amount) - fee: (optional) Flat fee in sats
- fee_rate: (optional) Fee rate in sats/vbyte
- inscriptionId: (optional) If provided, fetches the UTXO for this inscription
Returns:
psbt: The base64-encoded PSBT stringfee: Fee usedchange: Change output (if any)inputs_used: Number of UTXOs usedfee_rateandvsizeif fee_rate was used
- Never expose private keys to this server
- Use HTTPS in production
- Protect your API keys (do not commit them)
- Validate all input if you modify the code
- Run behind a firewall if on a public server
- Fork or clone this repo
- Add new endpoints or logic in
app.py - Write new tests in
tests/ - Use the PSBT output with your own signing wallet or service
TSS_SendBitcoin/
βββ app.py # Main Flask API
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ LICENSE # MIT License
βββ tests/ # Automated tests
β βββ test_psbt_creator.py
βββ examples/
β βββ bulk_requests.json # Example batch requests
βββ .gitignore
- Fork the repository
- Create your feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
MIT β see LICENSE
- Open an issue on GitHub
- Or start a discussion!
TSS: Bitcoin scripting made simple and open-source, scalable, and easy for everyone.