How to Accept Bitcoin Donations Without Requiring Donor Accounts
A donation service can avoid collecting names and email addresses while retaining minimal operational state.
Implementation approach
Issue an opaque random session token and store only its digest with an expiry. This token is for session lookup, not spending authority. Bitcoin is public and account-free donations are not guaranteed anonymous; IP logs, address reuse and chain analysis may reveal relationships. Expiry removes access to the session, not funds or accounting records.
Source code
1import secrets, hashlib
2
3def digest(token):
4 return hashlib.sha256(token.encode('ascii')).hexdigest()
5
6class Sessions:
7 def __init__(self): self.records={}
8 def create(self, address, now, ttl=900):
9 if type(ttl) is not int or ttl <= 0: raise ValueError('invalid ttl')
10 token=secrets.token_urlsafe(32)
11 self.records[digest(token)]=(address,now+ttl)
12 return token
13 def lookup(self, token, now):
14 row=self.records.get(digest(token))
15 return row[0] if row and now < row[1] else None
16
17if __name__ == '__main__':
18 s=Sessions(); token=s.create('fixture',100,10)
19 assert token not in s.records and s.lookup(token,109)=='fixture'
20 assert s.lookup(token,110) is NoneLocal validation
Run stage23-account-free-donations.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
