Smart Wallets
Smart wallets are the foundation of the SatsTerminal Borrow SDK. They provide secure, deterministic EVM accounts derived from Bitcoin wallet signatures.What is a Smart Wallet?
A smart wallet is an ERC-4337 smart contract account that:- Is derived deterministically from a Bitcoin signature
- Supports gasless transactions via account abstraction
- Enables session-based authorization for secure operations
- Provides multi-chain support with the same derivation
How Derivation Works
- User signs a deterministic message with their Bitcoin wallet
- The signature is used to derive EVM private keys
- A smart account address is computed from these keys
- The same BTC wallet always produces the same smart account
Signing Message Format
Loan Wallet # index allows multiple smart accounts per BTC wallet.
Multi-Index Architecture
Each user can have multiple smart wallets, indexed starting from 0:| Index | Purpose |
|---|---|
| 0 | Base wallet (portfolio, withdrawals) |
| 1+ | Loan wallets (one per loan) |
Why Multiple Wallets?
Using separate wallets per loan provides:- Isolation - Each loan’s collateral is isolated
- Clarity - Clear separation of funds
- Security - Compromised loan doesn’t affect others
- Tracking - Easier transaction history per loan
Signature Caching
The SDK caches signatures to avoid repeated signing prompts:Clearing Cached Signatures
Smart Account Features
Gasless Transactions
Smart accounts enable gasless transactions via ERC-4337:- Users don’t need ETH for gas
- Gas is paid by the protocol
- Transactions are bundled efficiently
Session Keys
Instead of signing every transaction, users authorize a session:Cross-Chain Support
The same Bitcoin signature derives different addresses per chain:Wallet States
Deployed vs Undeployed
Smart accounts can exist in two states:| State | Description |
|---|---|
| Undeployed | Address computed but contract not deployed |
| Deployed | Contract deployed on-chain |
Restoring Wallets
If a user switches devices, wallets can be restored:Security Considerations
Signature Security
- Signatures are stored locally (browser localStorage or provided storage)
- Never transmitted except for initial derivation
- Can be cleared via
clearSession()
Smart Account Security
- Controlled only by the derived keys
- Session keys have limited scope and expiry
- Multi-sig upgrades possible (future)
Best Practices
- Clear sessions on logout - Call
clearSession()when user disconnects - Use secure storage - Provide encrypted storage in production
- Monitor session expiry - Refresh sessions before they expire
- Validate addresses - Always verify smart account addresses match expectations