This enhanced example demonstrates how to use zk-fetch with Reclaim Protocol in a React application, with added features for mobile development and on-chain integration.
- π Zero-Knowledge Proofs: Generate verifiable proofs for API responses
- π± Mobile-Responsive: Optimized for mobile devices with responsive design
- π Multiple Examples: GET and POST requests with different API endpoints
- βοΈ On-Chain Ready: Transform proofs for smart contract verification
- π― Error Handling: Comprehensive error handling and user feedback
- π¨ Modern UI: Clean, modern interface with Tailwind CSS
- CoinGecko API - Fetch and prove active cryptocurrency count
- GitHub API - Verify public repository count for users
- JSONPlaceholder - Demonstrate POST requests with zkFetch
- Node.js (v24 or higher)
- An application ID and secret from Reclaim Protocol DevTool
# Clone the repository
git clone <repository-url>
cd reclaim-zkfetch-client-master
# Install dependencies
npm install
# Run post-install script for zkFetch setup
npm run postinstall
# Set up environment variables
cp .env.example .envEdit .env and add your Reclaim credentials:
REACT_APP_RECLAIM_APP_ID=your_app_id_here
REACT_APP_RECLAIM_APP_SECRET=your_app_secret_herenpm startThe app will open at http://localhost:3000
const data = await reclaim.zkFetch(url, fetchOptions, {
responseMatches: [
{
type: "regex",
value: 'pattern_to_match'
}
],
responseRedactions: [{
regex: 'pattern_to_redact'
}]
});The app automatically transforms proofs for smart contract verification:
const transformed = {
encodedProof: "0x...", // ABI-encoded proof data
extractedData: {...}, // Extracted values from the API
claimInfo: {...} // Claim metadata
};- CoinGecko: Extracts
active_cryptocurrenciescount - GitHub: Extracts
public_reposcount - JSONPlaceholder: Extracts the created post
id
- Mobile-first CSS with breakpoints
- Touch-friendly buttons and interactions
- Optimized font sizes and spacing
- Safe area support for modern devices
- Efficient proof generation
- Loading states for better UX
- Error boundaries for graceful failures
Add your own API example:
const examples = {
myapi: {
name: 'My Custom API',
url: 'https://api.example.com/data',
method: 'GET',
responseMatches: [{
type: 'regex',
value: '"value":(?<value>\\d+)'
}],
responseRedactions: [{
regex: '"value":(?<value>\\d+)'
}],
description: 'Custom API verification'
}
};Use the transformed proof in your smart contract:
function verifyProof(
bytes32 identifier,
address owner,
uint256 timestampS,
uint256 epoch,
bytes memory signatures
) external {
// Verification logic
}-
CORS Errors: Some APIs may have CORS restrictions. Use APIs that allow cross-origin requests.
-
Webpack Polyfills: The project includes necessary polyfills for browser compatibility.
-
Mobile Testing: Use responsive design mode in browser DevTools or test on actual devices.
Check the browser console for detailed logs:
- Raw proof data
- Transformation steps
- Error details
βββ src/
β βββ App.js # Main application component
β βββ App.css # Mobile-responsive styles
β βββ index.js # Application entry point
βββ public/
β βββ browser-rpc/ # zkFetch browser resources
βββ config-overrides.js # Webpack configuration
βββ script.sh # Post-install setup script
Feel free to submit issues and enhancement requests!
This project is open source and available under the MIT License.