Hacking out a decentralised energy storage solution in one week
And here are some learnings we’d like to share with you…
Welcome to the part 2 of Validity Labs’ Energy & Blockchain blog series. Previously, we have given an overview of decentralised technologies in the energy sector, in particular their advantages and potential use cases. We have also mentioned the Proof-of-Concept (PoC) that we built for a community battery use case over one week, which we call Battery-DAO.
In this post, we would like to share with you our motivation (sec. 1), the tech details (sec. 2) as well as some of the learnings (sec. 3) we had from #buidling this PoC. Feel free to jump to your preferred section. Spoiler: there is an easter egg 🐰 at the end.
Battery + DAO = Battery-DAO
On what did we spend one week? The idea of this Battery-DAO project is straightforward: Combining a battery with a DAO. In this case, the “Battery” is “community battery storage”, which could be used as an energy aggregator and balancer in a virtual power plant (VPP) or as a flexibility provider in a microgrid. “DAO” stands for the “Decentralised Autonomous Organisation”, a governance model powered by decentralised technology that operates according to preset encoded rules that enhances transparency from the beginning. It can be used for decision-making and investment. Both terms seems to be heavily explored in isolation in their respective fields, but the charm comes from linking these two together.
DAOs linked to renewable energy assets and storage could solve some of the hottest problems for the energy sector — give financial access to direct sustainable energy generation from local neighbourhoods and share the cost or gains fairly with all of the community owners. This potentially enables both financing of an asset which could otherwise not be afforded by the community members in isolation, allows right sizing of storage size for the community as a whole, rather than for individual prosumers/consumers alone, and allows more efficient balancing of energy supply and demand at the community level.
A Battery-DAO could accept investments in form of cryptocurrencies to build a distributed energy generation and storage system. Households that have a physical connection to the system could purchase energy on an agreed time interval. All the purchases from the battery can be accumulated and can then be redistributed back to investors as dividends. New investors can join at any time. Dividends would be calculated based on the amount of “shares” that they hold and their time of participation.
Take a quick look at our Battery-DAO PoC here. It consists of three parts:
- Project overview: project setup (Schema of the project), one graph (Generation of individual PV) showing the energy generation of individual solar panel and one graph showing the accumulated energy generation and battery charging profile (Accumulated PV generation)
- Energy Purchase: to purchase energy from the battery with
EmuDAItoken (a mock token that represents the widely-used stable token DAI developed by MakerDAO) and display the purchase order over time.
- Investment: to invest in the project with ETH and gives a transparent overview on current shareholders to the public.
Implemented in Web3
How did we build the PoC? We already learnt from the previous post that this project will experiment the serverless and decentralised web3 technology, to make both the energy system and the IT system decentralised. 🎉
The tech stack we used:
- Ethereum blockchain (more specifically Ropsten testnet)
- Truffle Suite: including Truffle framework, Ganache for testing and deployment, and Drizzle for frontend development.
- OpenZeppelin library from Zeppelin
- Web3.js library
- React + Redux
- Many more lovely packages and dev tools: Material-UI, Recharts, …
The main business logic was coded with Solidity in the form of smart contracts. We introduced the
BDAO token, which is a ERC20 security-like token, to reflect the amount of shares held by investors. Also, as mentioned above, an
EmuDAI token was introduced, to emulate the usage of such a stable token, which facilitates the pricing and purchase of electricity given their less volatile nature. There’s no stabilizing mechanism behind the mock token. The only reason why we didn’t directly use
DAI is due to the testnet. Last but not least, we have two other contracts to achieve the dividend mechanism.
BdaoDividend contract receives
EmuDAI tokens and calculate dividends based on the amount of
BDAO token possessed by investors, which is reclaimable at any point of time. Another contract
Snapshots is used to support the calculation, by taking snapshots of the balance of
With these smart contracts and some efforts in frontend development to give a simple but functional user interface, the minimum functionalities work in this PoC. (🚨Bugs are expected though, as only happy-path testing was performed there.)
Learning by doing
As you may have experienced from using or developing decentralised applications, it feels very different from interacting with a traditional web app. Clearly, there’s no need for a login button (at least for our use case). However, the additional step to confirm actions by confirming a transaction is not intuitive. 🤷♀️
Apart from those general remarks, we have encountered other issues when architecturing the product:
Responding time vs. Finality
When a consumer needs energy and has observed sufficient storage in the battery, they can start to place the purchase orders¹. To assure that the consumer’s electricity withdrawal (imagine your fridge) flows continuously over the purchasing period, we want to minimise the responding time, i.e. the time between the order placement 🧾, transaction confirmation ✅, and the delivery 🚚. The current Battery-DAO responds to the order and delivers energy at the moment of order placement². However, it takes more time to get the transaction mined (~minutes). If the DAO owners agree on introducing a benchmark for when a transaction is considered final, e.g. 6-block finality, the transaction could only be considered as settled after another 6 blocks are mined. This additional block finality leads to a longer responding time.
However, a hybrid payment structure could solve the problem. An example is to use a payment channel, where multiple parties (in our case, a consumer and the battery) can open an off-chain channel to settle the transactions (and therefore trigger the delivery) instantaneously provided sufficient deposit and then finalise the transaction on the main chain less frequently (e.g. on a daily, weekly or monthly basis).
Scheduling with vs. without pipeline
What if an order is placed when there is no electricity stored in the battery? One possibility is to keep the order in a pipeline and start the delivery when energy is available again from the battery. Another option is to reject the order directly due to the unforeseen (as we didn’t include any predictive tools) charging profile. We have chosen the first option because it’s more fun to implement. 🛠
The pipeline method also comes a potential problem of having an order that is too big compared to the net electricity remaining in the battery after other withdrawals are factored in. The solution could be adding a
cancelOrder functionality to cancel completely or partially one order in the pipeline. More aggressively, the DAO may allow stakeholders to vote such an order out of the pipeline if necessary.
More potentials in the governance
Our current implementation hasn’ t unleashed the full potential of a Decentralised Autonomous Organization. Besides the dividend payout inside a DAO, members of this Battery-DAO could cast votes on proposals regarding the system maintenance, device upgrade, change in fee mechanism, membership management, etc.
Improvements in tech
Building with early stage technologies implies bugs discovery and issue reporting of libraries while building our own solution. As always, we love to work with the above-mentioned open-source frameworks/tools/libraries. We have reported a couple of issues to the respective repos as result of work on this (and other) PoCs and projects. A huge thanks to other teams in the ecosystem. 👍
Thank you for staying with us until this point. We have just taken a quick look at our one-week PoC of Battery-DAO. We stress that we have oversimplified how a community battery enabled DAO would need to work in practice, but it demonstrates that if this much functionality can be built in a week, that more complex functionality can easily be added with more development time.
As we noted in the first blog there are many other use cases of Energy & Blockchain across generation, consumption, flexibility and mobility, are not limited to community battery.
If you find Energy & Blockchain interesting ❤️, we would love to discuss more with you. We are hosting a blockchain and energy roundtable in Zurich in June 2019 to discuss use cases, potential and challenges of decentralised energy sector in the Swiss and European energy markets. If you would like to receive an invitation when the logistics are finalised please let us know at energy ( at ) validitylabs.org
¹ In this simple PoC we only enable immediate purchase and withdrawal, e.g. an automated instruction from an IoT device or smart meter that a shortfall needs to be covered and therefore to purchase from the battery to fill it, but in a full product forward purchasing and optimisation would also be possible.
² As noted above, a simplification for this PoC.
Great thanks to Validity Labs colleagues for all the discussions, contributions, and support during conceptualisation and implementation of this PoC. A special thanks to Arran Kitson for his extensive effort put in reviewing this post.
If you enjoyed this article, feel free to clap many times or share with a friend. 👏
About the author
Qianchen Yu is a decentralised application (dApp) developer at Validity Labs. She holds an MSc. degree in Energy Science and Technology from ETH Zürich and a Diplôme d’Ingénieur from École Centrale de Marseille. Her expertise lies in digital transformation in energy and cleantech.
If you are interested in the use case of a decentralised peer-to-peer (P2P) energy system, you could take a look at her peer-reviewed paper or the complete thesis. (It is definitely not self-publicity 🤓)
About Validity Labs
Validity Labs is a leading provider of blockchain-based decentralized applications. Our journey started in 2015 with the Ethereum genesis block as the first blockchain education company. Today, Validity Labs is the technical partner of choice for a range of startups as well as large corporates, offering support and know-how in the areas of blockchain-enabled solutions, decentralized applications, tokenisation and more.