Blockchain Drive uses a single Solidity contract —Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ankit-bista/Final-Project/llms.txt
Use this file to discover all available pages before exploring further.
BlockchainDriveUnified — that combines quota management and file permission logic in one deployment. You set both STORAGE_ALLOC_CONTRACT and DRIVE_V2_CONTRACT to the same deployed address, and the backend connects to each function group through its own ABI interface. The contract is written for Solidity ^0.8.20 and has no external dependencies, so it compiles and deploys without modification on any EVM-compatible network.
Deployment
- Hardhat
- Remix
Deploy to your network
<network> with a network name defined in your hardhat.config.js (for example localhost, mumbai, or mainnet).The contract comment at the top of the file explicitly states: deploy ONE contract in Remix and set BOTH env vars to this address. The two ABIs used by the backend are compatible with the same contract.
Data structures
FileRecord
Stores the on-chain record of an uploaded file. ThefileId field holds the IPFS CID.
contracts/BlockchainDriveUnified.sol
AccessGrant
Stores a single permission grant for a (file, user) pair.contracts/BlockchainDriveUnified.sol
When
expiresAt is 0, the grant never expires. When it is non-zero, the contract compares it to block.timestamp at the time of each access check.File section functions
recordFile
Called by the backend on every successful upload. Records the uploader’s address, the IPFS CID, an optional custom hash, and the file size in bytes.contracts/BlockchainDriveUnified.sol
FileRecorded(uploader, fileId, customHash, sizeBytes).
shareFile
Grants a recipient access to a file. Only the file’s original uploader or the contract owner can call this function.contracts/BlockchainDriveUnified.sol
| Parameter | Description |
|---|---|
fileId | The IPFS CID of the file to share |
recipientAddress | Wallet address of the recipient |
role | "viewer" or "editor" |
expiryDays | Days until expiry; 0 means no expiry |
FileShared(fileId, recipient, role, expiresAt).
revokeAccess
Deactivates an existing access grant. SetsAccessGrant.active to false. Only the original uploader or the contract owner can revoke.
contracts/BlockchainDriveUnified.sol
AccessRevoked(fileId, userAddress).
canUserAccessFile
Pure read function (no gas cost). Returnstrue if the user is allowed to perform the given action on the file.
contracts/BlockchainDriveUnified.sol
action value | Who passes |
|---|---|
"view" | The file uploader, any active viewer grant, any active editor grant |
"edit" | The file uploader, any active editor grant |
false for any unknown action string.
The backend calls this function through the BlockchainService:
services/blockchain.js
Quota section functions
See Quota management for full details. The quota functions on the contract are:allocatePool(poolName, bytesAmount)
allocatePool(poolName, bytesAmount)
Owner-only. Creates a named storage pool. Emits
PoolAllocated. This function exists for ABI compatibility — it does not gate allocateUserQuota.allocateUserQuota(poolName, userAddress, bytesAmount)
allocateUserQuota(poolName, userAddress, bytesAmount)
Owner-only. Sets the quota limit for a wallet address. Sets the tier to
"CUSTOM" and activates the quota. If maxFiles is currently 0, it is set to type(uint256).max.updateQuotaAfterUpload(userAddress, fileSizeBytes)
updateQuotaAfterUpload(userAddress, fileSizeBytes)
Called after a successful upload. Reverts if the quota is not active or would be exceeded. Increments
usedBytes and filesUploaded, and recalculates usagePercent.refundQuota(userAddress, fileSizeBytes)
refundQuota(userAddress, fileSizeBytes)
Called when a file is deleted. Decrements
usedBytes and filesUploaded, and recalculates usagePercent. Does not revert if the refund would underflow — it clamps to zero instead.Events
All events are emitted to the chain and form the immutable audit trail.| Event | Parameters | Emitted by |
|---|---|---|
FileRecorded | address indexed uploader, string fileId, string customHash, uint256 sizeBytes | recordFile |
FileShared | string fileId, address indexed recipient, string role, uint256 expiresAt | shareFile |
AccessRevoked | string fileId, address indexed userAddress | revokeAccess |
QuotaUpdated | address indexed userAddress, uint256 usedBytes, uint256 quotaLimitBytes | updateQuotaAfterUpload |
QuotaRefunded | address indexed userAddress, uint256 refundedBytes | refundQuota |
Owner-only functions
TheonlyOwner modifier restricts allocatePool and allocateUserQuota to the deployer account. The owner address is set in the constructor to msg.sender.
contracts/BlockchainDriveUnified.sol
ADMIN_PRIVATE_KEY environment variable must correspond to the wallet that deployed the contract. The backend uses this key to sign all write transactions, including allocatePool, allocateUserQuota, recordFile, shareFile, and revokeAccess.