Cashu Mint (Nutshell)
6. Cashu Mint (Nutshell)
With LNbits configured as the payment backend, in this chapter we configure the Cashu Mint. The Mint is the core component of the Cashu infrastructure: it holds users' bitcoin and, in exchange, issues tokens ("digital coupons") that represent that value. By the end, the Mint will be ready to receive deposits and issue tokens in both sats and USD.
6.1 Configuring the Lightning Backend (LNbits)
Next, we will configure a new wallet in LNbits that will act as the main deposit for Mint users' funds. This wallet will be responsible for receiving sats when a user wants to deposit funds into the Mint, and also for sending sats when a user wants to withdraw them.
We go to the account created in the LNbits chapter, log in, and create the wallet. The following image shows the process.
Image 1: Creating a wallet for Mint deposits.
- Click on
Add a new wallet. - A window appears where we enter the wallet name; we set it to Cashu Mint. It can be any name, the important thing is that we know what that wallet will be used for.
- Add the wallet.
After it is created, we need to get the API key that will allow us to receive payments and pay invoices.
In the same way as in the previous chapter (LNbits) where we looked for the wallet id for transaction fees, we look for the Admin key.
Image 2: Admin key to make and receive payments in the Cashu Mint.
- Select the
Admin key. - Copy the key.
Now in the terminal we navigate to the app-data/cashu/ directory:
cd app-data/cashu
Edit the .env file:
nano .env
Then look for the following parameters:
# Use with LNbitsWallet
MINT_LNBITS_ENDPOINT=https://yourlnbits.com
MINT_LNBITS_KEY=gds87dskdsjhds71dsdsds2e
Where it says https://yourlnbits.com we put https://lnbits.cashu4community.xyz and where it says MINT_LNBITS_KEY we replace gds87dskdsjhds71dsdsds2e with the key we copied earlier 55739ee04e53437aba54fa8c9e4175b8. Leaving it as follows:
# Use with LNbitsWallet
MINT_LNBITS_ENDPOINT=https://lnbits.cashu4community.xyz
MINT_LNBITS_KEY=55739ee04e53437aba54fa8c9e4175b8
Save and exit the file ctrl+s and ctrl+x.
Restart the container docker-compose restart cashu and the changes will be applied.
6.2 Generating RPC Certificates
SSL certificates are necessary to connect via RPC to the Mint and execute remote commands, useful if we want to use Orchard to manage the Mint. To generate them, we move to the certs directory as follows:
cd app-data/cashu/certs
Execute the generate_certificates.sh script as follows:
./generate_certificates.sh
This script will generate all necessary certificates; we can verify it by running the following command:
ls .
ca_cert.pem ca_private.pem client_cert.pem client_private.pem generate_certificates.sh server_cert.pem server_private.pem
Image 3: List of files inside the certs directory.
After making these changes, restart the Docker container:
docker-compose restart cashu
6.3 Creating a New Keyset from the CLI
We will use mint-cli to rotate keysets and define the fee. We will do this for each unit in the Mint, whether sats or USD.
To find out which units are active in the Mint, we query the /v1/keysets endpoint. We will do it as follows; this can also be done from a browser by entering the URL:
curl https://mint.cashu4community.xyz/v1/keysets
The curl command returns the following:
{
"keysets": [
{
"id": "0145ee812683eaf8ce3859f2601c160d0c8f0d4139447848d0d6745350f3c4fb44",
"unit": "sat",
"active": true,
"input_fee_ppk": 100,
"final_expiry": null
}
]
}
E.g.: if we wanted to change the fee from 100 ppk (per-proof-of-knowledge) for sat (Bitcoin) to 50 ppk, we would execute the following inside the cashu container:
docker exec -it app_cashu bash
Once inside the container, execute:
poetry run mint-cli -h cashu next-keyset sat 50
This would return something like:
final_expiry = None
New keyset successfully created:
keyset.id = '01e5bac64190f22f2959558b15cbab9f06798958f253a59fbe4687a9d875e3c720'
keyset.unit = 'sat'
keyset.max_order = 64
keyset.input_fee_ppk = 50
0
If we now execute the command again:
curl https://mint.cashu4community.xyz/v1/keysets
It returns both keysets: the old one and the new one.
{
"keysets": [
{
"id": "0145ee812683eaf8ce3859f2601c160d0c8f0d4139447848d0d6745350f3c4fb44",
"unit": "sat",
"active": false,
"input_fee_ppk": 100,
"final_expiry": null
},
{
"id": "01e5bac64190f22f2959558b15cbab9f06798958f253a59fbe4687a9d875e3c720",
"unit": "sat",
"active": true,
"input_fee_ppk": 50,
"final_expiry": null
}
]
}
6.4 USD Stable Support with Blink in the Mint
In version 0.20.0 of Nutshell, USD support via Blink as a funding source was added. In the following steps we will explain what you need to do both in Blink and in the Cashu Mint.
As a requirement, we must have an account in Blink; we can create it directly at https://dashboard.blink.sv without needing to install the application. It is also available for Android and iOS. With the account already created, we access the administration panel at the same address.
After logging in, the account administration panel appears, showing the two wallets we have: one in sats and the other in USD, along with several other options. The one we are interested in is API Keys.
Image 4: Blink Administration Panel - API Keys.
- After selecting
API Keysin the options menu, the following screen appears where we can create a new API key.
Image 5: Creating a new API key.
- Click the button with the
+symbol.
A window appears where we enter a name to identify the use of the key, the lifetime of the API key, and the operations we will allow with it.
Image 6: API key parameters.
- Enter the name of the API key, something that suggests the use it will have.
- API key expiration time: select
Never. - In the operations that can be done with the API, select all of them.
- Click the
Createbutton to create the key.
After creating the key, a window appears only once where we can copy the API keys; it is recommended to back them up in a safe place. For our case, we are only interested in the one related to USD, but in case we want to use Blink as a funding account for the Mint in both USD and BTC, both keys will be necessary.
Image 7: API keys to connect to Blink BTC and USD accounts.
- Copy the key in a safe place (this will be the one we use to connect the Cashu Mint to Blink).
- Click the
Closebutton.
This way we have created the key we will use in the Mint. Now we return to the terminal on our VPS; we are in the cashu4cs-deploy directory and edit the .env file.
nano app-data/cashu/.env
Inside the file, look for the line that has MINT_DERIVATION_PATH=:
MINT_DERIVATION_PATH="m/0'/0'/0"
Go to the beginning of the line and insert the # symbol, leaving it like this:
# MINT_DERIVATION_PATH="m/0'/0'/0"
Then look for the line MINT_DERIVATION_PATH_LIST=:
# MINT_DERIVATION_PATH_LIST=["m/0'/0'/0'", "m/0'/0'/1'", "m/0'/1'/0'", "m/0'/2'/0'"]
Remove the # symbol and the values between double quotes m/0'/0'/1' and m/0'/1'/0', leaving it like this:
MINT_DERIVATION_PATH_LIST=["m/0'/0'/0'", "m/0'/2'/0'"]
Now look for the line MINT_BACKEND_BOLT11_USD=FakeWallet, remove the # symbol, and where it says FakeWallet put BlinkWallet, leaving it like this:
MINT_BACKEND_BOLT11_USD=BlinkWallet
Finally, look for the Blink connection:
# MINT_BLINK_KEY=blink_abcdefgh
Remove the # symbol and paste the key we created in the Blink panel earlier, leaving something like this:
MINT_BLINK_KEY=blink_7Sz978fgdFGjhhT6u8g1tDvruhdeiuyidfdZ1fnDFcPSXKag5uHuip2S1yPP2wHG
Save and exit the file ctrl+s and ctrl+x.
Restart the Cashu Mint Docker container:
docker-compose restart cashu
From here the Mint is ready to operate. We can send and receive payments in both sats and USD from compatible wallets such as cashu.me, El Caju, or Minibits.