Smart Carbon Credit System using Oracles, Blockchain, and Digital Identity Wallets
The repository is divided into two primary environments:
blockchain/: The core Hardhat project directory. Contains the Solidity smart contracts. Key contracts include theConsumerContract(handling load-balanced Oracle requests and carbon credit logic),Operator,MinimalForwarder(for meta-transactions), and mock tokens. It also contains TypeScript and Bash scripts for deployment and environment management.chainlink-node/: Contains the infrastructure and configuration for the chainlink nodes.web/: Contains the off-chain applications and services.frontend/: A React application built with Vite. It interacts with the backend API and the deployed smart contracts via the RPC exposed by the blockchain node.backend/: A Node.js/Express API that manages user authentication, interacts with a PostgreSQL database, and implements an EIP-2771 compatible relayer system to facilitate gasless meta-transactions for users. It also provides simulated external data endpoints.
To simulate the envisioned decentralized network, the testing pipeline is designed to be distributed across multiple Virtual Machines (VMs).
The infrastructure is split into three distinct roles:
This VM acts as the orchestrator of the test. It hosts the local blockchain network, deploys the contracts, and drives the automated testing pipeline.
- Setup the Node: Start your local blockchain node and RPC endpoint on this VM so that it is accessible to the other VMs.
- Define Chainlink Nodes: In the root of the
blockchain/directory on this VM, create a file namedmaster_nodes.txt. - Configure IP Addresses: Add the IP addresses of your Chainlink Node VMs to
master_nodes.txt, with one IP address per line. The testing pipeline will dynamically read this file to determine how many nodes to scale and target during the run. - Execute Tests: Run the master test script from this VM:
./run-all-tests.shThese VMs act as the decentralized oracle network. You can provision one or multiple VMs to test load balancing and system stress.
- Role: Run the Chainlink node software and connected database (e.g., PostgreSQL).
- Setup: The nodes must be configured to point to the RPC URL of the Blockchain VM. Their wallet addresses will be automatically authorized and funded by the scripts running on the Blockchain VM.
This VM isolates the frontend and backend environments from the blockchain infrastructure.
- Role: Runs the React/Vite web application and the Node.js Express backend.
- Setup:
- For the backend: Navigate to
web/backend/. Configure.envwith theRPC_URL(pointing to the Blockchain VM),FORWARDER_ADDRESS, andADMIN_PRIVATE_KEY. - For the frontend: Navigate to
web/frontend/. Configure your environment variables to point to the IP address of the Blockchain VM's RPC, the Backend API, and the newly deployed contract addresses.
- For the backend: Navigate to
For testing on a single machine or for development, you can run the entire stack locally using Docker.
This command spins up the Blockchain, Chainlink Node, Database, Backend API, and Frontend on your local machine.
# Start all containers (wiping previous DB to ensure synchronization)
docker compose down -v
docker compose up -dWait about 30-60 seconds for the Chainlink Node to initialize and become "Healthy" before proceeding.
We use a custom script that deploys contracts, funds accounts, creates the Chainlink Job via API, and updates your frontend/backend configurations automatically.
cd oracle-echosystem
npx hardhat run scripts/deploy-local.ts --network localhostWhat this script does:
- Deploys LinkToken, Operator, MinimalForwarder, and SatelliteCreditManager.
- Authorizes the Chainlink Node on the Operator contract.
- Funds the Node with ETH and the contracts with LINK.
- Logs into the Chainlink Node API and creates a new Direct Request Job using
job-spec.toml. - Updates
web/frontend/public/config.jsonand.envfiles with the new addresses and Job ID. - Copies the latest ABIs to the frontend/backend source folders.
- Open
http://localhost:5173in your browser to access the frontend dashboard. - Open
http://localhost:5000/docsto access the Backend API Swagger documentation. - Open
http://localhost:6688to access the Chainlink Operator UI.