Last active
December 4, 2023 00:59
-
-
Save callebtc/fb03c36c7f321710f19b54d9d7f766fc to your computer and use it in GitHub Desktop.
Nutshell: Mint a Cashu token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from cashu.wallet.wallet import Wallet | |
from cashu.core.settings import settings | |
async def main(): | |
settings.tor = False | |
wallet = await Wallet.with_db( | |
url="http://mint.url:3338", | |
db="wallet_db_path", | |
) | |
await wallet.load_mint() | |
await wallet.load_proofs() | |
# mint tokens into wallet, skip if wallet already has funds | |
print(f"Wallet balance: {wallet.available_balance} sat") | |
if wallet.available_balance <= 10: | |
invoice = await wallet.request_mint(100) | |
input(f"Pay this invoice and press any button: {invoice.bolt11}\n") | |
await wallet.mint(100, id=invoice.id) | |
# create 10 sat token | |
proofs_to_send, _ = await wallet.split_to_send(wallet.proofs, 10, set_reserved=True) | |
token = await wallet.serialize_proofs(proofs_to_send) | |
print(token) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment