Building a Wallet Management System
Learn how to implement a complete wallet management system with Blnk.
Overview
This tutorial will guide you through implementing a simple wallet management system using the Blnk Ledger. By the end, you’ll have built a system that can:
- Create customer wallets.
- Link wallets to customer identities.
- Support deposits and withdrawals from wallets.
- Create purpose-specific wallets (e.g. card balances).
- Enable transfers between wallets.
For this tutorial, we’ll use the Blnk TypeScript SDK for the implementation. If you prefer, you can also refer to the API reference for details on the available endpoints.
Designing your map
Before writing code, it’s crucial to design a money movement map that outlines how money moves in your system. This serves as the blueprint for your implementation.
For our wallet management system, here’s how funds will flow:
This map shows three key components:
@World
: Represents external funding sources and withdrawal destinations.Main Wallet
: The customer’s primary wallet for deposits and withdrawals.Card Wallet
: A second wallet for card-related transactions.
From our map, we can verify that:
- Customers can deposit money from external sources to their main wallet.
- Customers can withdraw money from their main wallet to external destinations.
- Customers can transfer money from their main wallet to their card wallet.
Set up your implementation
Based on our map, we’ll implement the following steps:
- Create a customer ledger to organise all customer wallets.
- Create customer identity for storing user information.
- Create a main wallet and link it to the identity.
- Implement deposit functionality.
- Implement withdrawal functionality.
- Create a card wallet and link it to the same identity.
- Fund the card wallet from the main wallet.
Prerequisites
Before starting, ensure you have:
- A running Blnk server instance (e.g. at
http://localhost:5001
). - An API key for Blnk (replace
YOUR_API_KEY
in the code examples). Required for authenticated requests. - The Blnk CLI installed or a connected Blnk Cloud workspace to view your ledger data.
Create customer ledger
First, we need to initialise Blnk and create a ledger to organise all customer wallets — main and card wallets.
You can also create separate ledgers for different wallet types, e.g., Customer Main Ledger
and Customer Card Ledger
, to keep your balances more organized.
Always save the ledger_id
in your database. You’ll use this ID to create balances for the customer wallets.
Create customer identity
Create your customer profiles with identities:
Always save the identity_id
in your database. You’ll use this ID to link balances to this identity or query all balances owned by this identity.
Create main wallet
Create a balance to represent the customer main wallet and link to the customer identity:
Always store the balance_id
in your database and associate it with the customer. You’ll use this ID for all future transactions involving this wallet.
Funding the main wallet
Use an internal balance to represent external deposit sources—such as bank accounts, cards, and other funding methods—responsible for funding a customer’s wallet:
Setting allow_overdraft
to true
enables the transaction to proceed even if the source balance lacks sufficient funds.
Withdrawals from the main wallet
You can use the same internal balance to represent external withdrawal destinations to ensure it is balances out your ledger, or you can allocate a separate internal balance specifically for withdrawals.
Creating a card balance
To create a card balance and link it to the customer:
Funding the card from main wallet
Record a transaction between both balances to fund your card balance:
Conclusion
You should now have a fully functional and scalable wallet management system.
As your application grows, you can expand its capabilities with features like transaction history, scheduled transfers, balance monitors, and notifications to enhance performance and user experience.
Can’t find your use case?
If you’re searching for a specific tutorial that isn’t included here, you’re welcome to contribute to our documentation by sharing your expertise or requesting a new tutorial in our Discord community.
We’re always thrilled to expand our resources with the help of our developer community!
Was this page helpful?