THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

How to Build an Embeddable Bitcoin Donation Widget

permalink THAMER
#bitcoin#donations#python#website

An embedded donation widget can display a public receiving address without giving the host page wallet API credentials.

Implementation approach

Serve a minimal HTML fragment from trusted configuration. Escape display text and restrict address characters. For cross-site embedding, use a dedicated iframe origin and a deliberate frame-ancestors policy. The example renders markup only, not a hosted service or QR image.

Source code

Python · 10 lines
1from html import escape
2import re
3
4def widget(address, label):
5    if not re.fullmatch(r'[a-zA-Z0-9]{14,90}',address): raise ValueError('unsafe address')
6    return '<section><h2>'+escape(label)+'</h2><code>'+escape(address)+'</code><p><a href="bitcoin:'+address+'">Open wallet</a></p></section>'
7
8if __name__ == '__main__':
9    html=widget('tb1qsyntheticfixture','<script>alert(1)</script>')
10    assert '<script>' not in html and '&lt;script&gt;' in html

Local validation

Run stage23-donation-widget.py with Python 3. Fixtures are not valid Bitcoin addresses. This is an educational example, not a production donation service. No SEND operation is included.

Related documentation

https://thamer.org/api

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects