This project is a prototype implementation of the paper “A Blockchain-Based Architecture for Energy Trading to Enhance Power Grid Stability.”
- 📜 Smart Contracts:
contracts/ - 📄 Processed Data:
data/- Data Format (📦 Source-Sundance):
- Consumer:[time(1-based, 24),demand(kW)]
- Prosumer:[time(1-based, 24),demand(kW),supply(kW)]
- Original consumption data:
data/consumer(prosumer)/historicaldata - Predicted consumption data:
data/consumer(prosumer)/predictiondata - Real consumption data:
data/consumer(prosumer)/realdata
- Data Format (📦 Source-Sundance):
- 📂 Simulation Output:
output/ - 🧠 Main Simulation Logic:
src/- configuration:
src/sg_config.py - contract compilation & deployment:
src/SmDeployments - Blockchain interaction:
src/Blockchain - EMS models:
src/Model - simulation entry point:
src/server.py
- configuration:
1️⃣ create a virtual environment (recommended)
python -m venv .BTA
source .BTA/bin/activate
python -m pip install -U pip
pip install -e .2️⃣ train models for each endpoint
python src/Model/trainModel.py3️⃣ start a local Ethereum node
# use hardhat
npm install --save-dev hardhat # install Hardhat (if not installed)
npx hardhat # create a project (if not created)
npx hardhat node # start local blockchain
# use ganache
# install ganache
ganache -p 7545 -i 1337
# revise RPC_URL, PRIVATE_KEY and CHAIN_ID in 'src/sg_config.py' according to your node4️⃣ compile and deploy smart contracts
python src/SmDeployments/compile.py
python src/SmDeployments/deploy.py
python src/SmDeployments/getOnChainInfo.py5️⃣ run the simulation
python src/server.py6️⃣ get results visualization
(You can run these directly, as example data is already provided for the simulation window [91, 105))
python src/Analysis/plot1.py
python src/Analysis/plot2-1.py
python src/Analysis/plot2-2.py
python src/Analysis/plot3.py
python src/Analysis/plot4.py7️⃣ modify configuration and re-run
# in src/sg_config.py
CONSUMER_NUMBER = 5
PROSUMER_NUMBER = 10
TIME_WINDOW_START = 91
TIME_WINDOW_END = 105If you change the number of consumers/prosumers:
# import sundance dataset in dir 'data/rawdata'
python src/DataBean/data_bean.pyre-run above steps again
This project is licensed under the MIT License - see the LICENSE file for details.