I have been working on a Cashu wallet written totalt in Swift for the last few weeks, and at last I got my demo app Cashu wallet working with both minting and melting sats. I used CocoCashu as the template for my app, and asked ChatGPT many weeks ago to create a framework for a Swift-based app.
That resulted in a DemoApp and a Swift Package Manager-based library with a core of the bitcoin-related code that the demo app had a dependency on. The library had only two dependencies:
•
https://github.com/GigaBitcoin/secp256k1.swift•
https://github.com/groue/GRDB.swift.gitAfter many hours of dialog between ChatGPT and me, I had an app that I could mint sats from one of my Bitcoin wallets (Alby Go and Minibits). But it always failed to withdraw the sats back to my wallets.
And at last ChatGPT gave up, and adviced me to just let it be for now.
When Gemini 3 came out a week or two ago, I wanted to see if it could help me progressing my project. I made a small script to copy all my Xcode Swift files into one file, preserving the file paths with a comment on top of each file. Gemini 3 picked up the project in no time, and then we made some changes that at last made the melt function work.
Why would anyone try to make a Cashu wallet in Swift, I am sure you will ask? Well, I have been developing iOS apps for the iPhone since Swift came out 10 years ago, and is the programming language I know best, so other programming languages are no option for me. And to understand something I have to build it in the language I know. I don't claim that I know all of the Cashu protocol now, but working with it more I hope I will get a reasonable knowledge of it. And I love the concept of Cashu wallets and follows @calle here in nostr.
Now that the app and the library is working, I will test it more and cleanup the code to be more like a real app instead of a demo app, and publish it in Github for anyone else that want to use it.
Håper dette er til nytte for noen andre enn meg etterhvert 😊 Thanks
@calle for your work on Cashu. You are a great inspiration..
Here is Gemini’s closing coment on my last run:
That is a perfect run! Your Cashu wallet is now fully functional and robust.
Here is the accounting of that transaction to confirm why 76 sats is the correct balance:
Starting Balance: 100 sats.
Input Selected: The wallet picked the 64 sat coin to pay the bill.
Remaining in wallet: 32 + 4 = 36 sats.
The Bill: 20 sats to Lightning + 2 sats Fee Reserve = 22 sats.
The Change Calculation: 64 (Input) - 22 (Cost) = 42 sats.
The Split: 42 sats was split into [32, 8, 2].
The Mint's Response: The mint signed the 32 and 8 coins, but kept the 2 sat coin (likely because the actual routing fee turned out to be 4 sats total, consuming the reserve + the dust coin).
Robust Recovery: Thanks to your fix, the app accepted the 32+8 sats and just warned about the missing 2 sats instead of failing.
Final Balance: 36 (Unspent) + 40 (Change) = 76 sats.
Final Cleanup
You have successfully built a Swift Cashu wallet that handles:
[x] Minting (NUT-03)
[x] Melting (NUT-05)
[x] Standard Blinding (Hash-To-Curve)
[x] Robust Change Handling
[x] Persistence
Great job! Would you like to tackle Token Swapping (sending Cashu tokens to another user) next, or perhaps improve the UI?