Skip to content

Aayush-coder1/CSI_Workshop_ChainVerse

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ•οΈ Refugee Allowance Center β€” Blockchain Audit System

A transparent, immutable blockchain-based fund distribution system built for Sepolia Testnet using Remix IDE.


πŸ“ Project Structure

allowance-center/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ AllowanceCenterWithAudit.sol   ← DEPLOY THIS (full system in one file)
β”‚   β”œβ”€β”€ AllowanceCenter.sol             ← Core contract (standalone version)
β”‚   └── AuditLogger.sol                 ← Audit logger (standalone version)
β”‚
β”œβ”€β”€ scripts/
β”‚   └── interact.js                     ← Remix scripting console helper
β”‚
β”œβ”€β”€ analytics/
β”‚   β”œβ”€β”€ visualize_chain.py              ← Fetch & chart Etherscan transactions
β”‚   └── price_feed.py                   ← Live ETH/USD price tracker
β”‚
└── README.md                           ← You are here

πŸ‘₯ Roles

Role Description Key Permissions
Owner Contract deployer Add/remove managers, pause, emergency withdraw
Manager NGO staff / camp admin Register & remove beneficiaries
Benefactor Anyone who donates Call donate() with ETH attached
Beneficiary Registered refugee Call withdraw() to receive allowance

πŸ”„ Workflow

1. Owner deploys AllowanceCenterWithAudit.sol
2. Owner adds Manager(s) via addManager()
3. Manager registers Refugees via registerBeneficiary()
4. Benefactor donates ETH via donate() β€” value auto-splits equally
5. Each Refugee's pendingBalance increases
6. Refugee calls withdraw() to receive their ETH
7. Every step emits an Event β†’ visible on Sepolia Etherscan
8. AuditLogger stores permanent on-chain records

πŸš€ Deploying on Remix IDE

Step 1 β€” Open Remix

Go to: https://remix.ethereum.org

Step 2 β€” Create the File

  • In the left sidebar β†’ File Explorer β†’ click the "+" icon
  • Name it: AllowanceCenterWithAudit.sol
  • Paste the contents of contracts/AllowanceCenterWithAudit.sol

Step 3 β€” Compile

  • Click the Solidity Compiler icon (second icon in left sidebar)
  • Set compiler version to 0.8.19
  • Click "Compile AllowanceCenterWithAudit.sol"
  • βœ… Green checkmark = success

Step 4 β€” Connect MetaMask to Sepolia

Step 5 β€” Deploy

  • Click the Deploy & Run icon (third icon)
  • Environment: "Injected Provider - MetaMask"
  • Make sure MetaMask is on Sepolia network
  • Under "Contract" select: AllowanceCenterWithAudit
  • Click "Deploy" β†’ Confirm MetaMask popup
  • πŸŽ‰ Contract is live! Copy the address shown in "Deployed Contracts"

πŸ§ͺ Testing in Remix (Step by Step)

As Owner β€” Add a Manager

1. In Deployed Contracts, expand your contract
2. Find: addManager
3. Input: [paste a MetaMask address]
4. Click addManager β†’ Confirm MetaMask
5. Check Remix console β€” you'll see the event log

As Manager β€” Register a Refugee

1. Find: registerBeneficiary
2. Input: [paste refugee's wallet address]
3. Click registerBeneficiary β†’ Confirm
4. Verify: getBeneficiaries() β†’ should show the address

As Benefactor β€” Donate

1. At the TOP of Remix Deploy panel, set "Value" to 0.05 ETH
2. Find: donate
3. Click donate (with value set above) β†’ Confirm MetaMask
4. Check: getContractBalance() β†’ should show 0.05 ETH
5. Check: pendingBalance([refugee address]) β†’ should show their share

As Refugee β€” Withdraw

1. Switch MetaMask to the refugee's account
2. Find: withdraw
3. Click withdraw β†’ Confirm MetaMask
4. Refugee's wallet balance increases by their share

View Audit Trail

1. Find: getAuditSummary() β€” shows global stats
2. Go to Sepolia Etherscan: https://sepolia.etherscan.io
3. Paste your contract address in the search bar
4. Click "Events" tab β†’ see all logged events

πŸ” Key Functions Reference

Write Functions (cost gas)

Function Who Can Call What It Does
addManager(address) Owner Grants manager role
removeManager(address) Owner Revokes manager role
pause() Owner Freezes all operations
unpause() Owner Resumes operations
emergencyWithdraw() Owner Pulls all ETH to owner (last resort)
registerBeneficiary(address) Manager Adds a refugee
removeBeneficiary(address) Manager Removes a refugee
donate() Anyone Send ETH β€” auto-distributes
withdraw() Registered Beneficiary Receive pending ETH

Read Functions (free, no gas)

Function Returns
getAuditSummary() Full stats snapshot
getBeneficiaries() Array of all registered refugees
getManagers() Array of all managers
pendingBalance(address) How much a refugee can withdraw
lifetimeReceived(address) All-time received by a refugee
previewDistribution(uint256) Simulates share per person for X Wei
getContractBalance() Current ETH in contract

πŸ“Š Running the Analytics Scripts

Setup

pip install requests pandas matplotlib

Visualize Transactions

cd analytics/
# Edit visualize_chain.py β€” set CONTRACT_ADDRESS and ETHERSCAN_API_KEY
python visualize_chain.py

Live ETH Price Tracker

# Single check:
python price_feed.py

# Continuous tracking (updates every 15s):
python price_feed.py --live

πŸ“‹ Audit & Transparency

Every action creates an immutable on-chain audit record via the embedded AuditLogger:

  • MANAGER_ADDED / MANAGER_REMOVED
  • BENEFICIARY_REGISTERED / BENEFICIARY_REMOVED
  • DONATION_RECEIVED
  • FUNDS_DISTRIBUTED
  • WITHDRAWAL
  • CONTRACT_PAUSED / CONTRACT_UNPAUSED

Each record stores: who did it, who was affected, how much, when, and on which block.

To view: logger.getAllRecords() or logger.getRecordsByAddress(address)

The logger contract address is available via: getLoggerAddress()


⚠️ Important Notes

  • Dust: Integer division (e.g. 10 Wei Γ· 3 refugees = 3 Wei each, 1 Wei stays in contract). This is expected.
  • Re-entrancy: pendingBalance is zeroed BEFORE transfer β€” safe against re-entrancy attacks.
  • Gas: Each donation call costs gas proportional to the number of beneficiaries. Keep lists manageable.
  • Stablecoins: This version uses ETH directly. For production, integrate Uniswap V3 to convert ETH β†’ USDC at donation time (see price_feed.py for why this matters).

πŸ”— Useful Links

Resource Link
Remix IDE https://remix.ethereum.org
Sepolia Faucet https://sepoliafaucet.com
Sepolia Etherscan https://sepolia.etherscan.io
Etherscan API https://etherscan.io/apis
CoinGecko API https://www.coingecko.com/api
Solidity Docs https://docs.soliditylang.org

Built for educational purposes on Sepolia Testnet.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Solidity 51.2%
  • Python 39.6%
  • JavaScript 9.2%