{"id":17780714,"url":"https://github.com/flowstake/strava-connect","last_synced_at":"2025-04-01T19:36:17.223Z","repository":{"id":259622296,"uuid":"871294140","full_name":"flowstake/strava-connect","owner":"flowstake","description":"Strava to Blockchain Integration connects Strava activity data with Ethereum-compatible blockchains, enabling you to record activities on-chain, reward users with tokens, and implement staking. It supports gas optimization, off-chain storage, and cheating prevention via validation mechanisms.","archived":false,"fork":false,"pushed_at":"2024-10-26T22:32:30.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-11-23T21:04:07.377Z","etag":null,"topics":["ipfs"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flowstake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-11T16:48:23.000Z","updated_at":"2024-10-26T22:32:33.000Z","dependencies_parsed_at":"2024-10-26T23:45:44.420Z","dependency_job_id":"76a064df-99e3-4484-9bfa-371a10bbcb46","html_url":"https://github.com/flowstake/strava-connect","commit_stats":null,"previous_names":["flowstake/strava-connect"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fstrava-connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fstrava-connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fstrava-connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fstrava-connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flowstake","download_url":"https://codeload.github.com/flowstake/strava-connect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227764353,"owners_count":17816378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ipfs"],"created_at":"2024-10-27T03:03:38.655Z","updated_at":"2024-12-02T16:43:15.588Z","avatar_url":"https://github.com/flowstake.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# strava-connect\n\n# **Strava to Blockchain Integration**\n\nThis project demonstrates how to connect Strava activity data with Ethereum-compatible blockchains like Ethereum or Polygon. The goal is to fetch user activity data from Strava and store or verify it on-chain using smart contracts.\n\n## **Table of Contents**\n\n- [Overview](#overview)\n- [Prerequisites](#prerequisites)\n- [Project Structure](#project-structure)\n- [Getting Started](#getting-started)\n  - [1. Strava API Integration](#1-strava-api-integration)\n  - [2. Smart Contract Setup](#2-smart-contract-setup)\n  - [3. Web3 Integration](#3-web3-integration)\n- [Optional Enhancements](#optional-enhancements)\n  - [A. Gas Optimization](#a-gas-optimization)\n  - [B. Tokenization (Rewards \u0026 Staking)](#b-tokenization-rewards--staking)\n  - [C. Cheating Prevention](#c-cheating-prevention)\n- [Deployment](#deployment)\n- [Contributing](#contributing)\n- [License](#license)\n\n---\n\n## **Overview**\n\nThis project connects physical activity data, such as running or cycling, from Strava with Ethereum-compatible smart contracts (Ethereum, Polygon, etc.). The data can be stored or verified on the blockchain for various purposes like activity tracking, rewards, or staking systems.\n\nFeatures include:\n- Fetching activity data from Strava (distance, time, pace, etc.)\n- Recording activity data on a blockchain using Solidity smart contracts.\n- Optional token rewards or staking mechanics for users.\n- Verification mechanisms to prevent cheating or data manipulation.\n\n---\n\n## **Prerequisites**\n\nBefore starting, ensure you have the following installed:\n- [Node.js \u0026 npm](https://nodejs.org/en/download/)\n- [Hardhat](https://hardhat.org/) or [Truffle](https://www.trufflesuite.com/)\n- MetaMask (or any Ethereum-compatible wallet)\n- Access to an Ethereum-compatible testnet (e.g., Goerli, Polygon Mumbai)\n- [Strava Developer Account](https://developers.strava.com/)\n\n---\n\n## **Project Structure**\n\n```\n├── contracts/                   # Solidity smart contracts\n│   ├── StravaActivityTracker.sol # Main contract to record activity data\n│   ├── ActivityToken.sol         # (Optional) ERC20 contract for token rewards\n│   └── StravaActivityStaking.sol # (Optional) Smart contract for staking activities\n├── scripts/                     \n│   └── deploy.js                 # Deployment script using Hardhat\n├── src/                         \n│   ├── components/               # React/React Native components\n│   └── utils/                    # Utility functions (e.g., Web3 interaction, Strava API fetch)\n├── README.md                     # This README file\n├── package.json                  # Node.js project metadata\n├── hardhat.config.js             # Hardhat configuration file\n├── .env                          # Environment variables (Strava API keys, etc.)\n```\n\n---\n\n## **Getting Started**\n\n### **1. Strava API Integration**\n\nYou need to register an application on the Strava Developer Portal to access the Strava API. After registering, you'll receive your `client_id`, `client_secret`, and `redirect_uri` for OAuth authentication.\n\n#### **Step 1: Install Dependencies**\n\nInstall required libraries for OAuth and making HTTP requests:\n```bash\nnpm install react-native-app-auth node-fetch ethers dotenv ipfs-http-client\n```\n\n#### **Step 2: Implement OAuth Flow**\n\nCreate a function to authenticate the user and retrieve their Strava activity data:\n```javascript\nimport { authorize } from 'react-native-app-auth';\n\nconst config = {\n  issuer: 'https://www.strava.com/oauth/authorize',\n  clientId: process.env.STRAVA_CLIENT_ID,\n  clientSecret: process.env.STRAVA_CLIENT_SECRET,\n  redirectUrl: 'yourapp://oauthredirect',\n  scopes: ['activity:read'],\n  serviceConfiguration: {\n    authorizationEndpoint: 'https://www.strava.com/oauth/authorize',\n    tokenEndpoint: 'https://www.strava.com/oauth/token',\n  },\n};\n\nexport const authenticateStrava = async () =\u003e {\n  const authResponse = await authorize(config);\n  return authResponse.accessToken;\n};\n```\n\n#### **Step 3: Fetch Activity Data**\n\nUse the access token to request activity data from Strava’s API:\n```javascript\nexport const fetchActivities = async (accessToken) =\u003e {\n  const response = await fetch(\n    `https://www.strava.com/api/v3/athlete/activities?access_token=${accessToken}`\n  );\n  const activities = await response.json();\n  return activities;\n};\n```\n\n---\n\n### **2. Smart Contract Setup**\n\nWrite a basic Solidity smart contract to store the user’s Strava activity data (distance and duration) on-chain.\n\n#### **Solidity Contract (StravaActivityTracker.sol)**\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ncontract StravaActivityTracker {\n    struct Activity {\n        address user;\n        uint256 distance;\n        uint256 duration;\n        uint256 timestamp;\n    }\n\n    mapping(address =\u003e Activity[]) public activities;\n\n    event ActivityRecorded(address indexed user, uint256 distance, uint256 duration, uint256 timestamp);\n\n    function recordActivity(uint256 _distance, uint256 _duration) external {\n        activities[msg.sender].push(Activity({\n            user: msg.sender,\n            distance: _distance,\n            duration: _duration,\n            timestamp: block.timestamp\n        }));\n        \n        emit ActivityRecorded(msg.sender, _distance, _duration, block.timestamp);\n    }\n}\n```\n\n---\n\n### **3. Web3 Integration**\n\nOnce the contract is deployed, interact with it using `ethers.js` to record activities.\n\n#### **Client-Side Code for Recording Activity**\n\n```javascript\nimport { ethers } from 'ethers';\n\nconst provider = new ethers.providers.Web3Provider(window.ethereum);\nconst signer = provider.getSigner();\n\nconst contractAddress = 'YOUR_DEPLOYED_CONTRACT_ADDRESS';\nconst contractABI = [/* ABI from your Solidity contract */];\n\nconst contract = new ethers.Contract(contractAddress, contractABI, signer);\n\nexport const recordActivity = async (distance, duration) =\u003e {\n  const tx = await contract.recordActivity(distance, duration);\n  await tx.wait();\n  console.log(\"Activity recorded successfully\");\n};\n```\n\n---\n\n## **Optional Enhancements**\n\n### **A. Gas Optimization**\n\nTo optimize gas usage, batch multiple activities into one transaction or store large data like GPS coordinates off-chain using IPFS.\n\n#### **Batch Activity Recording**\n\n```solidity\nfunction recordActivities(uint256[] memory _distances, uint256[] memory _durations) external {\n    require(_distances.length == _durations.length, \"Mismatched arrays\");\n\n    for (uint256 i = 0; i \u003c _distances.length; i++) {\n        activities[msg.sender].push(Activity({\n            user: msg.sender,\n            distance: _distances[i],\n            duration: _durations[i],\n            timestamp: block.timestamp\n        }));\n    }\n\n    emit ActivitiesRecorded(msg.sender, _distances.length);\n}\n```\n\n#### **Store GPS Data on IPFS**\n\n```javascript\nimport { create } from 'ipfs-http-client';\n\nconst ipfs = create('https://ipfs.infura.io:5001');\n\nexport const uploadGpsDataToIPFS = async (gpsData) =\u003e {\n  const gpsBuffer = Buffer.from(JSON.stringify(gpsData));\n  const result = await ipfs.add(gpsBuffer);\n  return result.cid.toString(); // This is the IPFS CID\n};\n```\n\n---\n\n### **B. Tokenization (Rewards \u0026 Staking)**\n\nCreate an ERC20 token to reward users for completing activities or allow them to stake tokens on their own performance.\n\n#### **ERC20 Token Contract**\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\ncontract ActivityToken is ERC20 {\n    address public activityContract;\n\n    constructor() ERC20(\"ActivityToken\", \"ATK\") {\n        activityContract = msg.sender;\n    }\n\n    function mintReward(address user, uint256 amount) external {\n        require(msg.sender == activityContract, \"Only the activity contract can mint\");\n        _mint(user, amount);\n    }\n}\n```\n\n---\n\n### **C. Cheating Prevention**\n\nImplement P2P attestation via QR codes or NFC, or integrate Chainlink oracles for data validation.\n\n#### **P2P Attestation with QR Codes**\n\nGenerate and scan QR codes to validate user activities.\n\n```javascript\nimport QRCode from 'qrcode.react';\n\nconst generateQR = (userAddress) =\u003e {\n  return \u003cQRCode value={userAddress} size={128} /\u003e;\n};\n```\n\n---\n\n## **Deployment**\n\nDeploy the smart contracts to an Ethereum-compatible network like Goerli or Polygon.\n\n#### **Deploy Using Hardhat**\n\n1. Configure the deployment script in `scripts/deploy.js`:\n   ```javascript\n   const StravaActivityTracker = await ethers.getContractFactory(\"StravaActivityTracker\");\n   const contract = await StravaActivityTracker.deploy();\n   ```\n\n2. Run the deployment:\n   ```bash\n   npx hardhat run scripts/deploy.js --network goerli\n   ```\n\n---\n\n## **Contributing**\n\nContributions are welcome! Feel free to open issues or pull requests with improvements or suggestions.\n\n---\n\n## **License**\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowstake%2Fstrava-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflowstake%2Fstrava-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowstake%2Fstrava-connect/lists"}