From 638801e2e6985aa4051884fb0e8e3a4c7fa1e979 Mon Sep 17 00:00:00 2001 From: elnosh Date: Tue, 13 Aug 2024 09:50:17 -0500 Subject: [PATCH] examples on wallet ops --- wallet/examples/wallet.go | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 wallet/examples/wallet.go diff --git a/wallet/examples/wallet.go b/wallet/examples/wallet.go new file mode 100644 index 0000000..7f05658 --- /dev/null +++ b/wallet/examples/wallet.go @@ -0,0 +1,42 @@ +package main + +import ( + "fmt" + + "github.com/elnosh/gonuts/cashu" + "github.com/elnosh/gonuts/cashu/nuts/nut04" + "github.com/elnosh/gonuts/wallet" +) + +func main() { + config := wallet.Config{ + WalletPath: "./cashu", + CurrentMintURL: "http://localhost:3338", + } + + wallet, err := wallet.LoadWallet(config) + + // Mint tokens + mintQuote, err := wallet.RequestMint(42) + + // Check quote state + quoteState, err := wallet.MintQuoteState(mintQuote.Quote) + if quoteState.State == nut04.Paid { + // Mint tokens if invoice paid + proofs, err := wallet.MintTokens(mintQuote.Quote) + } + + // Send + includeFees := true + token, err := wallet.Send(21, "http://localhost:3338", includeFees) + fmt.Println(token.ToString()) + + // Receive + receiveToken, err := cashu.DecodeToken("cashuAeyJ0b2tlbiI6W3sibW...") + + swapToTrustedMint := true + amountReceived, err := wallet.Receive(*receiveToken, swapToTrustedMint) + + // Melt (pay invoice) + meltResponse, err := wallet.Melt("lnbc100n1pja0w9pdqqx...", "http://localhost:3338") +}