Sunlight, traded next door — predictive peer-to-peer energy trading for neighborhood microgrids.

Try it live → https://microtrade-pro.onrender.com/

The demo runs in your browser against a live 9-household microgrid. You can watch the day-ahead auction clear, step the simulation clock an hour at a time, place your own orders, and verify the ledger end to end.

Inspiration

Most rooftop solar is wasted — exported for pennies while the evening peak is bought back at full price. The grid takes its cut both ways, and the carbon savings are never counted. We wanted a market where a neighborhood trades sunlight with itself, settled fairly and verifiably.

The specific numbers that convinced us this was worth building: retail power in the model runs $0.284/kWh while a feed-in tariff pays only $0.068/kWh. A household with solar on its roof is paid roughly a quarter of what its neighbour pays for the same kilowatt-hour, a few metres down the street. Meanwhile local solar is worth $0.108/kWh to generate — comfortably below retail — so the physics of the neighbourhood say the power should never have left the roof in the first place.

The second thing that convinced us: you cannot trade a promise you cannot verify. Two neighbours agreeing to swap 4 kWh tomorrow need to know who delivered, what it was worth, and what happens if the sun does not show up. That requirement — not the market mechanics — is what shaped the whole architecture.

Live 3D microgrid: nine homes around a community battery

What it does

MicroTrade Pro turns a 9-home neighborhood into an autonomous power market. Each home runs a forecasting agent that predicts its own supply and demand, bids into a day-ahead auction, signs forward contracts, and settles delivery — with every green kilowatt-hour retired as an auditable climate claim.

It is one closed loop: weather → forecast → order → contract → delivery → certificate, with a hash anchoring every step so that any settlement can be traced back to the exact forecast that justified its price.

Predict. Every agent trains its own ridge-ensemble model on three weeks of meter history plus live weather, publishing 48-hour load and solar curves with honest uncertainty bands.

The model is deliberately ordinary: per-household ridge regression on roughly 2,000 15-minute samples, 15 standardized features (five daily sin/cos harmonics, weekend flag, cooling- and heating-degree terms, cloud cover, irradiance), L2 regularization at λ = 1.4, solved as a 15×15 normal-equation system. No dependencies, no GPU, no training pipeline to babysit — it re-fits in under a second per home.

The honest part is the error accounting. A held-out 72-hour tail is never seen during fitting, and error is reported as WAPE across that window: 6.5–10.7% per household, about 9% across the fleet. Measured against a naive persistence baseline, skill ranges from 0% on the least predictable home to 62% on the most predictable one, averaging ~27% across the fleet. We quote the range rather than the best case because the difference between homes is the whole point — a home with a heat pump and four kids is not as forecastable as a solar-only home.

Uncertainty is not a decoration on the chart. Residual spread, horizon decay and cloud cover widen the P10–P90 band, and those bounds feed straight into the agent's bid and ask shading and the quantity it is willing to commit.

Trade. Each morning the agents bid into a uniform-price double auction. One clearing price per hour. Matched trades become forward contracts: the buyer escrows payment, the seller stakes a 12% bond that is slashed if the sun doesn't deliver.

Bids rank high, asks rank low, and the book clears while bid ≥ ask — every matched pair in a delivery hour settles at the midpoint of the marginal bid and ask. Simple, legible, and it avoids discriminating between neighbours, which matters when the counterparty is someone you have to wave to in the morning.

The collateral is what makes a forward contract a forward contract rather than a wish. The buyer escrows the full notional at creation; the seller locks a bond worth 12% of it. Delivery within 5% of the contracted quantity settles in full. A shortfall is pro-rated and the bond compensates the buyer. A community battery runs as a tenth participant, bidding for cheap midday solar and discharging into the 17:00–21:00 scarcity window — which both smooths the local price curve and gives rooftop owners a second buyer for their surplus.

Day-ahead double auction and forward book

Settle. Delivery is metered hourly against the contract. Escrow releases, shortfalls slash bonds, and each delivered green kWh mints a GreenREC. The ledger is a signed, Merkle-committed chain — and the same contracts live on a public testnet (below).

Settlement is hourly and metered, not assumed. At each delivery slot the engine compares metered delivery against the contract, releases escrow, slashes the bond on a shortfall, and mints one GreenREC per delivered green kWh — unique serial, tied to the settlement transaction hash, so a certificate cannot be double-counted inside the community or retired twice.

Underneath is a purpose-built, EVM-inspired chain: every write is an Ed25519-signed transaction with a monotonically increasing nonce, gas metering and a fee, executing inside deterministic contracts (EnergyForward, GreenREC, MicroTradeToken) that emit events the explorer renders without trusting the client. Each block commits its transactions to a Merkle root and references its parent hash. The Verify chain button recomputes every stored root and link from scratch — tamper with a single byte of any block body and the check fails.

Verifiable settlement ledger with RECs

Agents. Nine autonomous household agents — forecasters, market makers, a battery operator — coordinate the whole day while you sleep.

They are eight homes plus the community battery, and each runs the same loop: forecast, derive a risk-shaded limit order, bid, and hold collateral. Sellers ask at least LCOE plus battery wear; buyers bid at most retail minus the network charge. Three strategy profiles (conservative, balanced, aggressive) set both how much of the forecast surplus or deficit the agent is willing to offer and how far the limit price shades toward the uncertain tail. Turn autonomy off and you can place those orders by hand — the point is that the market works either way, and that the human is a participant in it rather than a supervisor of it.

The smart contracts — deployed, not vaporware

The settlement layer is real Solidity, deployed on public testnets. V2 is the hardened build: reentrancy guard, staked seller bonds via depositBond, unfunded-crowding protection via cancelUnfunded, oracle-gated settlement and minting, zeroed balances before external calls. Full sources in contracts/ (MIT).

V1 got us a working end-to-end contract; V2 is the one we would actually defend. The changes that mattered most were all about who is allowed to do what: V1 let the buyer report its own delivery, so anyone could settle a contract they had not fulfilled. V2 routes settlement and minting through an authorized oracle, moves the seller bond into an explicit depositBond call so a contract can never exist uncollateralised, adds cancelUnfunded so an unfunded contract cannot be left hanging in the book, and zeroes balances before every external call.

Honest scope: these are testnet deployments, self-reviewed and hardened — not a third-party audit. The code is open, the chains are public, and every claim above is checkable on-chain at the addresses linked above.

How we built it

React + Three.js live 3D microgrid, Node/Express deterministic simulation engine, dependency-free ridge regression, Ed25519-signed PoA ledger, Solidity V2 on Base Sepolia. Demo film cut with Hyperframes from real app capture, voiced with Deepgram.

The client is a pure view layer over a single deterministic simulation node that owns the world state and exposes it over HTTP and Server-Sent Events. That constraint is what makes the demo trustworthy: every number on screen can be reproduced from the ledger and the simulation seed, and npm test re-checks the auction, the ridge model and the ledger's integrity on every run. Weather comes from Open-Meteo with a one-hour disk cache and a deterministic synthetic fallback, so the demo behaves identically online and offline.

What we're proud of

  • The loop is complete. Most energy-trading demos stop at a dashboard. Ours runs from a weather forecast through a signed order book to an on-chain settlement with a retireable certificate — with no step faked.
  • The uncertainty is real. Probability bands drive the order book rather than decorating it, and the error numbers are reported against a held-out window.
  • It is inspectable. Anyone can click Verify chain and recompute every Merkle root, or open the deployed contract on a public explorer and read the same rules.
  • It runs where people live. No new hardware: smart-meter reads, inverter telemetry and a weather feed. A utility or co-op could pilot this over existing AMI.

What we learned

  • The forecast is the product. The auction code was the easy part. Knowing what a specific roof will produce at 14:00 tomorrow — and admitting how uncertain that is — is what makes the market work at all.
  • Collateral beats trust. Nothing changed about neighbourly behaviour when we added bonds; what changed was that a contract could survive a dispute.
  • Honest numbers win. We rewrote our own headline accuracy claim after checking it against the state file. The fleet average is ~27% skill against naive, not the 62% best case — and the smaller number is more defensible in front of judges.

What's next

Mainnet pilot with a real community battery, Chainlink oracle feeds for settlement, third-party audit of V2, and mobile metering via smart-plug integrations. Beyond that: real smart-meter adapters, zk-attested forecasts, a hardhat-deployed L2 testnet, and multi-day rolling auctions with demand-response events and flexibility markets for heat pumps.

Links

Built With

Share this project:

Updates

Submission history