C# library for the Cashu protocol - a Chaumian e-cash system built on Bitcoin/Lightning.
dotnet add package DotNutThe main entry point is the Wallet class, which exposes a fluent builder for connecting to a mint and performing operations.
var wallet = Wallet.Create()
.WithMint("https://testnut.cashu.space")
.WithMnemonic("your twelve word mnemonic phrase here...")
.WithCounter(new InMemoryCounter());var mintHandler = await wallet
.CreateMintQuote()
.WithAmount(1000)
.WithUnit("sat")
.ProcessAsyncBolt11();
// Pay the Lightning invoice
Console.WriteLine(mintHandler.GetQuote().Request);
// After payment, mint the tokens
List<Proof> proofs = await mintHandler.Mint();// From a cashuB... token string
List<Proof> proofs = await wallet
.Swap()
.WithDLEQVerification()
.ProcessAsync(); // pass token string to SwapBuilder or use FromInputs()
// From raw proofs
List<Proof> rebalanced = await wallet
.Swap()
.FromInputs(existingProofs)
.ProcessAsync();var meltHandler = await wallet
.CreateMeltQuote()
.WithInvoice("lnbc...")
.WithUnit("sat")
.ProcessAsyncBolt11();
List<Proof> changeProofs = await meltHandler.Melt(inputProofs);IEnumerable<Proof> recovered = await wallet
.Restore()
.ProcessAsync();var token = new CashuToken
{
Unit = "sat",
Tokens = [new CashuToken.Token { Mint = "https://testnut.cashu.space", Proofs = proofs }]
};
string v4 = token.Encode("B"); // cashuB... (CBOR, compact)
string v3 = token.Encode("A"); // cashuA... (JSON)
string uri = token.Encode("B", makeUri: true); // cashu:cashuB...
var decoded = CashuTokenHelper.Decode(v4, out string version);// Mint tokens locked to a pubkey
var mintHandler = await wallet
.CreateMintQuote()
.WithAmount(500)
.WithP2PkLock(new P2PKBuilder { Pubkeys = [pubkey], SignatureThreshold = 1 })
.ProcessAsyncBolt11();
// Spend P2PK-locked tokens by signing during swap
List<Proof> proofs = await wallet
.Swap()
.FromInputs(lockedProofs)
.WithPrivkeys([privKey])
.ProcessAsync();If you need raw protocol access without the wallet abstraction:
var httpClient = new HttpClient { BaseAddress = new Uri("https://testnut.cashu.space/") };
var api = new CashuHttpClient(httpClient);
var info = await api.GetInfo();
var keysets = await api.GetKeysets();
var mintQuote = await api.CreateMintQuote<PostMintQuoteBolt11Response, PostMintQuoteBolt11Request>(
"bolt11", new PostMintQuoteBolt11Request { Amount = 1000, Unit = "sat" }
);var wallet = Wallet.Create()
.WithMint("https://testnut.cashu.space")
.WithWebsocketService(new WebsocketService());
var ws = await wallet.GetWebsocketService();
// subscribe to quote state changes, proof state updates, etc.| NUT | Description |
|---|---|
| 00 | Cryptographic primitives & token format |
| 01 | Mint public key distribution |
| 02 | Keysets and keyset IDs |
| 03 | Swapping tokens |
| 04 | Minting tokens |
| 05 | Melting tokens |
| 06 | Mint info |
| 07 | Token state check |
| 08 | Lightning fee return |
| 09 | Token restoration |
| 10 | Spending conditions |
| 11 | Pay-to-Public-Key (P2PK) |
| 12 | DLEQ proofs |
| 13 | Deterministic secrets (BIP39) |
| 14 | Hash Time-Locked Contracts (HTLC) |
| 17 | WebSocket subscriptions |
| 18 | Payment requests |
| 20 | Signature on Mint Quote |
| 23 | BOLT11 |
| 25 | BOLT12 |
| 26 | Payment Request Bech32m Encoding |
| 27 | Nostr Mint Backup |
| 28 | Pay-to-Blinded-Key (P2BK) |
TODO:
| NUT | Description |
|---|---|
| 15 | Multipath payments |
| 21 | Clear Authentication |
| 22 | Blind Authentication |
- .NET 8.0+
MIT - see LICENSE.