Docs Field verification guide
Guides

Field verification guide

Use SwiftProof to verify that field agents actually visited the sites they reported visiting.

Use cases

Integration pattern

Create a chain when a field visit is scheduled. The agent confirms on-site by opening the link — SwiftProof captures their GPS to verify they were actually at the location.

schedule-visit.js
const chain = await sp.chains.create({
  title: `Site visit — \${site.address}`,
  metadata: {
    siteId: site.id,
    agentId: agent.id,
    visitType: 'pre-disbursement-inspection',
  },
  actors: [
    { event: 'arrived',   actor: agent.name },
    { event: 'inspected', actor: agent.name },
    { event: 'departed',  actor: agent.name },
  ],
  expires_in_hours: 24,
});

// Send to agent before the visit
await sendSMS(agent.phone,
  `Your visit confirmation links for \${site.address}: \${chain.handoffs[0].confirmation_url}`);

Verifying location accuracy

After the agent confirms, verify the chain and compare the captured GPS coordinates against the expected site location.

verify-visit.js
function distanceKm(a, b) {
  // Haversine formula
  const R = 6371;
  const dLat = (b.lat - a.lat) * Math.PI / 180;
  const dLng = (b.lng - a.lng) * Math.PI / 180;
  const x = Math.sin(dLat/2) ** 2 +
    Math.cos(a.lat * Math.PI/180) * Math.cos(b.lat * Math.PI/180) *
    Math.sin(dLng/2) ** 2;
  return R * 2 * Math.atan2(Math.sqrt(x), Math.sqrt(1 - x));
}

const proof = await sp.chains.verify(chainId);
const arrival = proof.trail.find(s => s.event === 'arrived');
const dist = distanceKm(arrival.coordinates, site.coordinates);

if (dist > 0.1) { // More than 100m from site
  flagForReview('Agent confirmed too far from site', dist);
}