Skip to content

FarmerRegistry.sol

The first contract deployed. Stores verified farmer identities, MAAIF national IDs, GPS farm data references, and cooperative memberships. All other contracts depend on it.

  • Stores the canonical list of verified farmers
  • Links MAAIF national farmer IDs to cooperative wallet addresses
  • References GPS polygon IPFS CIDs (not raw coordinates on-chain)
  • Controls which cooperative agents can register farmers (AGENT_ROLE)
  • GFW deforestation check is recorded at registration
struct Farmer {
string maaifFarmerId; // e.g. "UG-KAS-2024-001234"
address cooperativeWallet; // The cooperative this farmer belongs to
bytes32 farmBoundaryIpfsCid; // IPFS CID hash of GeoJSON polygon
uint256 farmAreaHectares; // Scaled by 100 (e.g. 240 = 2.40 ha)
uint256 registrationTimestamp;
bool gfwDeforestationFree; // Confirmed at registration
bool active;
}
mapping(address => Farmer) public farmers; // wallet → Farmer
mapping(string => address) public maaifToWallet; // maaifId → wallet
// Register a new farmer (AGENT_ROLE required)
function registerFarmer(
address farmerWallet,
string calldata maaifFarmerId,
bytes32 farmBoundaryIpfsCid,
uint256 farmAreaHectares,
bool gfwDeforestationFree
) external onlyRole(AGENT_ROLE);
// Verify a farmer is registered and active
function isRegistered(address farmerWallet) external view returns (bool);
// Get farmer data (used by BatchToken.sol at mint time)
function getFarmer(address farmerWallet) external view returns (Farmer memory);
// Deactivate a farmer (COOP_ROLE — for deceased, relocated, or fraudulent records)
function deactivateFarmer(address farmerWallet) external onlyRole(COOP_ROLE);
RoleGranted toPermission
DEFAULT_ADMIN_ROLEAsiliChain deployer multisigGrant/revoke all roles
COOP_ROLECooperative walletDeactivate farmers, update cooperative metadata
AGENT_ROLEField agent walletsRegister new farmers
Field agent opens agent app (or MAAIF NTS API called)
MAAIF NTS: returns farmerID + GPS polygon GeoJSON
API: GFW check on farm polygon centroid
API: pinGeoJSON(polygon) → Pinata → IPFS CID returned
API: FarmerRegistry.registerFarmer(wallet, maaifId, ipfsCid, area, gfwStatus)
HCS: REGISTERED event written
event FarmerRegistered(
address indexed farmerWallet,
string maaifFarmerId,
address indexed cooperative,
uint256 timestamp
);
event FarmerDeactivated(
address indexed farmerWallet,
address indexed deactivatedBy,
uint256 timestamp
);