> Markdown version of https://www.imranjan.cn/projects/p-accessaudit for AI agents and other programs. It carries the same public information as the web page. Built 2026-11-30.

Dec 2025 - Jan 2026

# AccessAudit - On-Chain Access Approval & Audit System

## Sepolia Deployment & Etherscan Verification + Dune Event Analytics Dashboard

Tags: Blockchain, Smart Contract, Web3, Data Analytics

![AccessAudit - On-Chain Access Approval & Audit System](https://www.imranjan.cn/images/projects/accessaudit-2026/cover.png)

Click to enlarge

#### Project Resources

View the open-source smart contract code on GitHub, check the verified contract on Etherscan, or explore the Dune Analytics dashboard.

[ GitHub Repository](https://github.com/narmi924/AccessAudit)
[ View on Etherscan](https://sepolia.etherscan.io/address/0xaED732B1F4Dcc0DD062434F0dE4ec1Cf61a3c60E)
[ Dune Dashboard](https://dune.com/audreyre/accessaudit-sepolia-event-analytics)

### Background & Motivation

While preparing a Web3-related project for graduate school applications, I realized that my interest in Web3/decentralized systems—particularly their trustable execution, auditability, and open data interfaces—needed to go beyond conceptual understanding. I needed to validate my depth of comprehension and engineering capabilities through hands-on projects.

Therefore, starting in early December, I deliberately chose a minimal topic that would showcase a complete Web3 capability loop: on-chain access approval and audit logs (Access Approval & Audit Logs), with the goal of producing verifiable outputs "from zero to deployment."

I chose this topic because it simultaneously covers the three most essential aspects of decentralized applications:

![](https://www.imranjan.cn/images/projects/accessaudit-2026/icons/highlight-1.svg)

##### Role-Based Access Control

How real-world access approval, data authorization, and role management are expressed on-chain.

![](https://www.imranjan.cn/images/projects/accessaudit-2026/icons/highlight-2.svg)

##### Auditable Event Logs

On-chain data's "verifiable interface" and how to construct audit trails using events.

![](https://www.imranjan.cn/images/projects/accessaudit-2026/icons/highlight-3.svg)

##### On-Chain Data Analytics

Transforming event logs into metrics, charts, and dashboards to provide presentable analytical evidence.

### Technology Stack

This project utilizes a modern Web3 development toolchain, forming a complete technical loop from smart contract development to on-chain deployment and data analytics.

#### Blockchain Platform

Ethereum Sepolia TestnetChain ID: 11155111Solidity ^0.8.20OpenZeppelin Contracts

#### Development Tools

Foundry (forge/cast/anvil)WSL UbuntuGit & GitHub

#### Infrastructure

Alchemy RPCMetaMaskEtherscan

#### Data Analytics

Dune AnalyticsPostgreSQL (Dune SQL)

### Learning Path & Resources

To avoid "concept-only learning without engineering execution," I adopted a "toolchain + minimal project-driven" approach, primarily referencing public videos and tutorial sites to complete onboarding and hands-on practice:

My strategy was not "complete all courses" but rather "learn while doing": every time I mastered a key concept (contracts/transactions/events/topics/RPC/testing), I immediately implemented it in the AccessAudit project and verified its functionality, ensuring I could produce externally verifiable outputs.

#### Tutorial Videos (Bilibili)

[智能合约公开课（PKUBA）](https://www.bilibili.com/video/BV12v4y1R77o)
[Web3审计与安全（PKUBA）](https://www.bilibili.com/video/BV19vBjYqEYn)
[Solidity 零基础入门](https://www.bilibili.com/video/BV1S5pqeBEfp)
[Foundry 入门实战](https://www.bilibili.com/video/BV1wS1WYoEan)

#### Tutorial Sites

[LeapWhale 教程](https://leapwhale.com)
[UseWeb3](https://www.useweb3.xyz)
[CryptoZombies](https://cryptozombies.io)

#### Official Docs

[Foundry Book](https://book.getfoundry.sh/)
[OpenZeppelin](https://docs.openzeppelin.com/contracts)
[MetaMask Docs](https://docs.metamask.io/)
[Alchemy Docs](https://www.alchemy.com/docs)

#### Community Resources

[Ethereum Stack Exchange](https://ethereum.stackexchange.com)
[EthResear.ch](https://ethresear.ch)

### Contract Design & Implementation

#### **Contract Goal: On-Chain Access Approval & Audit (Minimal but Extensible)**

The AccessAudit contract I implemented is a minimalist "access request—approval decision—audit trail" system with the following core design:

##### Roles

Using OpenZeppelin's AccessControl, I defined APPROVER\_ROLE as the approver role; the deployer/admin is responsible for granting roles.

##### Requests

Users submit access requests via requestAccess(payloadHash). I use payloadHash to represent a digest (hash) of the "accessed resource/dataset/permission scope," avoiding uploading sensitive information directly on-chain.

##### Decisions

Approvers approve or reject a request via decide(id, approved).

##### Events

Key state changes are written to on-chain logs via events, such as AccessRequested and AccessDecided. Events are the "factual records" of on-chain audits and the foundation for subsequent data analysis.

#### **AccessAudit Smart Contract**

Although simple, this design covers typical organizational access control logic at the system level: who can initiate, who can approve, how approval results are traceable, and how to standardize "audit evidence" written on-chain.

#### AccessAudit Smart Contract

solidity

code.solidity

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/AccessControl.sol";

contract AccessAudit is AccessControl {
    bytes32 public constant APPROVER_ROLE = keccak256("APPROVER_ROLE");

    struct Request {
        address requester;
        bytes32 payloadHash; // hash(datasetId || purpose || timestamp)
        uint64 createdAt;
        bool decided;
        bool approved;
    }

    uint256 public nextId;
    mapping(uint256 => Request) public requests;

    event AccessRequested(uint256 indexed id, address indexed requester, bytes32 payloadHash);
    event AccessDecided(uint256 indexed id, address indexed approver, bool approved);

    constructor(address admin) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
    }

    function requestAccess(bytes32 payloadHash) external returns (uint256 id) {
        id = nextId++;
        requests[id] = Request({
            requester: msg.sender,
            payloadHash: payloadHash,
            createdAt: uint64(block.timestamp),
            decided: false,
            approved: false
        });
        emit AccessRequested(id, msg.sender, payloadHash);
    }

    function decide(uint256 id, bool approved) external onlyRole(APPROVER_ROLE) {
        Request storage r = requests[id];
        require(!r.decided, "Already decided");
        r.decided = true;
        r.approved = approved;
        emit AccessDecided(id, msg.sender, approved);
    }
}
```

#### **Toolchain & Engineering (Foundry + WSL)**

I completed the full engineering workflow using the Foundry toolchain in a WSL Ubuntu environment:

##### forge

Compile contracts, run unit tests, execute deployment scripts (supporting dry-run and broadcast)

##### cast

Interact with contracts via command line, send transactions, query on-chain data (call/logs/receipt, etc.)

##### anvil

Local chain for rapid iteration validation (later migrated to Sepolia)

#### **Unit Testing: Ensuring Trustworthiness via "Verifiable Failure/Success"**

I wrote at least three types of unit tests for the contract, covering key security and logic branches:

01

##### Request Creation Correctness

ID auto-increment, request storage correctness, event emission

02

##### Permission Control Correctness

Only accounts with APPROVER\_ROLE can call decide (includes revert tests)

03

##### State Non-Replay

Already-decided requests cannot be decided again (includes revert tests)

### Deployment to Sepolia & Verification

To ensure external credibility, I deployed the contract to the Ethereum Sepolia testnet and completed a full verifiable evidence chain:

Starting from zero understanding of "what is a wallet/address/private key/test token," I completed testnet account setup and minimal fund management (only for gas), understood the role of RPC (the "entry point" for on-chain read/write), and obtained a usable Sepolia RPC via Alchemy. Finally, I completed Etherscan source code verification (Verified), making the source code, ABI, and method signatures publicly queryable.

#### Contract Information

NetworkEthereum Sepolia

Chain ID11155111

StatusVerified ✓

Contract Address

0xaED7...c60E

#### Verified Contract on Etherscan

![Verified Contract on Etherscan](https://www.imranjan.cn/images/projects/accessaudit-2026/contract-verified.png)Verified Contract on Etherscan

#### Key Transactions

##### ① Deploy Contract

**Tx Hash:** 0xfc08...91ef

Deployed AccessAudit contract and granted DEFAULT\_ADMIN\_ROLE to the deployer address.

##### ② Grant APPROVER\_ROLE

**Tx Hash:** 0xb39f...d53d

Granted APPROVER\_ROLE to a designated approver address to enable access request approvals.

##### ③ Request & Approve Access

**Request Tx:** 0x582f...f622

**Decide Tx:** 0x7ec6...19b5

User requested access with a hashed payload, and approver approved the request, emitting corresponding events.

#### Contract Deployment Transaction

![Contract Deployment Transaction](https://www.imranjan.cn/images/projects/accessaudit-2026/deploy-tx.png)Contract Deployment Transaction

![Access Request Transaction (Event Log)](https://www.imranjan.cn/images/projects/accessaudit-2026/request-tx.png)Access Request Transaction (Event Log)

![Access Decision Transaction (Event Log)](https://www.imranjan.cn/images/projects/accessaudit-2026/decide-tx.png)Access Decision Transaction (Event Log)

### Dune Event Analytics & Visualization Dashboard

After completing on-chain deployment and interaction, I further used Dune to transform on-chain events into readable statistical results and visualization dashboards. My approach was to directly analyze using Dune's sepolia.logs raw log table rather than relying on "pre-parsed project tables," demonstrating my understanding of EVM event structure:

I filtered logs by contract\_address for this contract; used topic0 (event signature hash) to distinguish different events: AccessRequested / AccessDecided; and used topic1 (indexed parameter) to correlate the same request's id, thereby joining requests and approval decisions.

#### Dune Analytics Dashboard Overview

![Dune Analytics Dashboard Overview](https://www.imranjan.cn/images/projects/accessaudit-2026/dune-dashboard.png)Dune Analytics Dashboard Overview

#### Core SQL Queries

##### Daily Access Requests

Count the number of AccessRequested events per day by filtering logs with the contract address and event signature (topic0).

#### Daily Access Requests

sql

code.sql

```sql
WITH req AS (
  SELECT
    date_trunc('day', block_time) AS day
  FROM sepolia.logs
  WHERE contract_address = 0xaed732b1f4dcc0dd062434f0de4ec1cf61a3c60e
    AND topic0 = 0x4295d04501e96b624f8e12689680e8383400ad570e624f8ec44cf306960a72e5
)
SELECT
  day,
  count(*) AS request_cnt
FROM req
GROUP BY 1
ORDER BY 1;
```

![Daily Request Volume Chart](https://www.imranjan.cn/images/projects/accessaudit-2026/daily-requests.png)Daily Request Volume Chart

##### Daily Approval Rate

Join AccessRequested and AccessDecided events on request\_id (topic1) to compute the approval rate per day.

#### Daily Approval Rate

sql

code.sql

```sql
WITH req AS (
  SELECT
    block_time AS request_time,
    topic1 AS request_id_raw
  FROM sepolia.logs
  WHERE contract_address = 0xaed732b1f4dcc0dd062434f0de4ec1cf61a3c60e
    AND topic0 = 0x4295d04501e96b624f8e12689680e8383400ad570e624f8ec44cf306960a72e5
),
dec AS (
  SELECT
    topic1 AS request_id_raw,
    (data = 0x0000000000000000000000000000000000000000000000000000000000000001) AS approved
  FROM sepolia.logs
  WHERE contract_address = 0xaed732b1f4dcc0dd062434f0de4ec1cf61a3c60e
    AND topic0 = 0x5859b9143a003cc5b61124a86acd1a3e4f2b7061c6900be7b94d54262e278cb1
),
joined AS (
  SELECT
    date_trunc('day', r.request_time) AS day,
    d.approved
  FROM req r
  LEFT JOIN dec d ON r.request_id_raw = d.request_id_raw
)
SELECT
  day,
  count() AS requests,
  sum(CASE WHEN approved THEN 1 ELSE 0 END) AS approved_cnt,
  CAST(sum(CASE WHEN approved THEN 1 ELSE 0 END) AS double) / count() AS approval_rate
FROM joined
GROUP BY 1
ORDER BY 1;
```

![Daily Approval Rate Chart](https://www.imranjan.cn/images/projects/accessaudit-2026/approval-rate.png)Daily Approval Rate Chart

### Project Summary

Through this project, I completed a full engineering practice from smart contract development, testnet deployment, source code verification, to on-chain data analytics:

GitHub RepositoryIncludes contract source code, tests, deployment scripts, environment config examples, and reproduction instructions ✓

Sepolia ContractDeployment and interaction records viewable on block explorer, Etherscan source verification ✓

Dune DashboardSQL visible, charts visible, dashboard shareable ✓

#### Core Takeaways: Systematic Understanding From 0 to 1

##### Complete Engineering Loop

Understood and practiced: contracts, accounts, transactions, gas, RPC, testnet, deployment, interaction, receipts, event logs

##### Technical Carrier of On-Chain "Auditability"

Understood the technical carrier of on-chain "auditability": event logs (topics/data)

##### On-Chain Data Analysis Capability

Able to directly use on-chain raw logs for analysis (Dune SQL) and output visualization dashboards

##### Web3 Security & Best Practices

More concrete understanding of "access control is a security baseline": role models, permission validation, state non-replay, etc.

If I continue to deepen this work, I plan to extend more realistic audit metrics, such as approval latency (request\_time to decide\_time), rejection rate, active requesters, and role change audit statistics, gradually migrating from testnet to a more realistic on-chain environment.

## Other pages

- [Home](https://www.imranjan.cn/index.md)
- [About me](https://www.imranjan.cn/about.md)
- [Projects](https://www.imranjan.cn/projects.md)
- [Photography](https://www.imranjan.cn/gallery.md)
- [LCIMS Cloud](https://www.imranjan.cn/projects/p-lcims.md)
- [imranjan.cn](https://www.imranjan.cn/projects/p-portfolio.md)
- [Open-source tools](https://www.imranjan.cn/projects/p-open-source.md)
- [Gatehouse](https://www.imranjan.cn/projects/p-gatehouse.md)
- [PlusOne](https://www.imranjan.cn/projects/p-plusone.md)
- [Gantry](https://www.imranjan.cn/projects/p-gantry.md)
- [BYOF Agent](https://www.imranjan.cn/projects/p-byof-agent.md)
- [Shopping Copilot by KI](https://www.imranjan.cn/projects/p-shopping-copilot.md)
- [Look2Act](https://www.imranjan.cn/projects/p-look2act.md)
- [Eye Touch - Real-time Eye Tracking and Gaze Control System](https://www.imranjan.cn/projects/p-eyetouch.md)
- [China Collegiate Computer Competition—Mobile Application Innovation Contest](https://www.imranjan.cn/projects/p-yigui.md)
- [Nilufar Restaurant Expense Management System](https://www.imranjan.cn/projects/p-nilufar.md)
- [Voice-Interactive LED Light Panel](https://www.imranjan.cn/projects/p-led.md)
- ["Mengsheng Cup" Electronic Design Competition](https://www.imranjan.cn/projects/p-msb.md)
- [NUS SOC SWS 2024](https://www.imranjan.cn/projects/p-nus.md)

中文版本：https://www.imranjan.cn/zh/projects/p-accessaudit.md
