Crypto wallet database schema
Users' wallets holding balances in assets, with on-chain transactions.
5 tables, 5 relationships
Opens as a new diagram you can change. Free.
Tables
users
- iduuid not null
- emailtext not null
- created_attimestamptz not null
crypto_assets
- iduuid not null
- symboltext not null
- nametext not null
- decimalsinteger not null
- created_attimestamptz not null
wallets
- iduuid not null
- user_id> usersuuid not null
- addresstext not null
- networktext not null
- created_attimestamptz not null
balances
- iduuid not null
- wallet_id> walletsuuid not null
- asset_id> crypto_assetsuuid not null
- amountnumeric(36,18) not null
- created_attimestamptz not null
chain_transactions
- iduuid not null
- wallet_id> walletsuuid not null
- asset_id> crypto_assetsuuid not null
- tx_hashtext not null
- amountnumeric(36,18) not null
- confirmed_attimestamptz
- created_attimestamptz not null
As PostgreSQL
The same diagram exports to MySQL, MariaDB, SQLite, SQL Server and Oracle, and to Prisma, Drizzle, SQLAlchemy and Convex models.
CREATE TABLE "balances" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"wallet_id" UUID NOT NULL,
"asset_id" UUID NOT NULL,
"amount" NUMERIC(36,18) DEFAULT 0 NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "chain_transactions" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"wallet_id" UUID NOT NULL,
"asset_id" UUID NOT NULL,
"tx_hash" TEXT NOT NULL UNIQUE,
"amount" NUMERIC(36,18) NOT NULL,
"confirmed_at" TIMESTAMPTZ,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "crypto_assets" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"symbol" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"decimals" INTEGER NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "users" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"email" TEXT NOT NULL UNIQUE,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE "wallets" (
"id" UUID DEFAULT gen_random_uuid() NOT NULL,
"user_id" UUID NOT NULL,
"address" TEXT NOT NULL UNIQUE,
"network" TEXT NOT NULL,
"created_at" TIMESTAMPTZ DEFAULT now() NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "wallets" ADD CONSTRAINT "fk_wallets_user_id" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "balances" ADD CONSTRAINT "fk_balances_wallet_id" FOREIGN KEY ("wallet_id") REFERENCES "wallets" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "balances" ADD CONSTRAINT "fk_balances_asset_id" FOREIGN KEY ("asset_id") REFERENCES "crypto_assets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "chain_transactions" ADD CONSTRAINT "fk_chain_transactions_wallet_id" FOREIGN KEY ("wallet_id") REFERENCES "wallets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE "chain_transactions" ADD CONSTRAINT "fk_chain_transactions_asset_id" FOREIGN KEY ("asset_id") REFERENCES "crypto_assets" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION;More Finance templates
- Double-entry accountingChart of accounts, journals and balanced journal entries per period.
- Banking coreCustomers, accounts, cards, transactions and transfers between accounts.
- Expense managementEmployees submit expense reports with receipts for policy checks and approval.
- InvoicingClients, invoices with line items and tax rates, and payments received.
- Personal budgetingAccounts, categorised transactions and monthly budgets per category.
- Loan servicingBorrowers, loan products, loans with repayment schedules and payments.
- Insurance policiesPolicyholders, products, policies with coverages, premiums and claims.
- PayrollPay periods, payslips with earnings and deduction lines per employee.
- CrowdfundingCampaigns with reward tiers, backers' pledges and creator updates.
Start with one diagram, free
One diagram with two branches, no card needed. Upgrade when your team needs more.