PiggyBank lets you lock SOL on-chain until a time of your choosing, then unlock it once the timer expires. It’s small on purpose — the point is to show how a Rails app talks to a custom Anchor program: parsing its IDL, Borsh-encoding instructions, and reading the resulting accounts back off the chain.
If Mercado shows payments and WalletTrain shows breadth, PiggyBank shows the
solrengine-programs gem doing the unglamorous-but-essential work of speaking a
program’s binary language from Ruby.
What it does
- Lock SOL with a time-based expiration
- Unlock once the lock expires
- Real-time lock list updates over WebSocket
- Wallet sign-in via SIWS
The program
PiggyBank drives the Cyfrin PiggyBank Anchor program on devnet:
- Program ID —
ZaU8j7XCKSxmmkMvg7NnjrLNK6eiLZbHsJQAc2rFzEN - Account layout — 8-byte discriminator + 32-byte destination pubkey + 8-byte
u64expiration - Instructions —
lock(amount, expiration)andunlock()
How a lock happens
The split of responsibility is the interesting part — the server encodes, the client signs:
1. Client generates a fresh keypair for the lock account
2. Server Borsh-encodes the instruction data (amount + expiration) from the IDL
3. Wallet signs and sends the transaction (client-side)
4. Lock accounts are queried straight from the chain and rendered as a list
5. Once a lock's expiration passes, the unlock instruction becomes available
The Rails database stores almost nothing about the locks themselves — they live on
Solana, and solrengine-programs decodes their raw account bytes back into Ruby
objects (PiggyBank::Lock) for display, with a live countdown ticking down to each
expiration.
The SolRengine gems behind it
- auth — SIWS wallet sign-in
- rpc — fresh blockhashes and on-chain account reads
- programs — IDL parsing + Borsh encoding for
lock/unlock - realtime — WebSocket updates to the lock list