Skip to content

fix(add-batch): mint per-batch provenance descriptor instead of fixed placeholder CID - #1350

Open
saidai-bhuvanesh wants to merge 1 commit into
Nitya-003:mainfrom
saidai-bhuvanesh:fix/1236-per-batch-ipfs-descriptor
Open

fix(add-batch): mint per-batch provenance descriptor instead of fixed placeholder CID#1350
saidai-bhuvanesh wants to merge 1 commit into
Nitya-003:mainfrom
saidai-bhuvanesh:fix/1236-per-batch-ipfs-descriptor

Conversation

@saidai-bhuvanesh

Copy link
Copy Markdown
Contributor

Summary

Fixes #1236

frontend/src/app/add-batch/page.tsx passed the literal CID "QmYwAPJhy5n2aBhajbN7yXq3TqK6Lj5ee2ov3333333333" to contract.createBatch(...) for every batch, so every on-chain BatchCreated event stored an identical ipfsCID, destroying the value of batch-specific provenance data.

Fix

Build a per-batch provenance descriptor from the batch's own data (batchId, cropType, quantity, farmerName, origin, description, recordedAt) and hash it with ethers.id(...) (sha-256) to produce a unique, deterministic descriptor that is minted on-chain instead of the constant placeholder. Each batch now records a distinct ipfsCID that uniquely identifies that batch's data.

The repo currently has no IPFS pinning integration configured, so a real resolvable CID isn't available yet. A TODO marks the spot to swap this descriptor for a real IPFS pin (Pinata / web3.storage / nft.storage) once configured — at which point ipfsDescriptor is replaced by the returned CID.

- "QmYwAPJhy5n2aBhajbN7yXq3TqK6Lj5ee2ov3333333333", // 46-char valid IPFS CID
+ const provenanceMetadata = {
+   batchId: batch.batchId, cropType: batch.cropType, quantity: batch.quantity,
+   farmerName: batch.farmerName, origin: batch.origin,
+   description: batch.description || "Initial harvest recorded",
+   recordedAt: batch.createdAt || new Date().toISOString(),
+ };
+ const ipfsDescriptor = ethers.id(JSON.stringify(provenanceMetadata));
+ // ... ipfsDescriptor passed as the ipfsCID arg

Files

  • frontend/src/app/add-batch/page.tsx

Notes

The on-chain mint path runs only when hasMetaMask() is true, so the existing component tests (jsdom, no window.ethereum) do not exercise this block and remain unaffected.


This PR was created by an AI agent (OpenHands) on behalf of @saidai-bhuvanesh.

… placeholder CID

add-batch/page.tsx passed the literal CID
'QmYwAPJhy5n2aBhajbN7yXq3TqK6Lj5ee2ov3333333333' to contract.createBatch
for every batch, so every on-chain BatchCreated event stored an identical
ipfsCID. Build a per-batch provenance descriptor from the batch's own data
and hash it with ethers.id (sha-256) to produce a unique deterministic
descriptor minted on-chain. TODO marks the spot to swap for a real IPFS
pin once a pinning integration is configured.

Closes Nitya-003#1236
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

@openhands-agent is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mint per-batch IPFS CID, not a fixed placeholder

2 participants