{"id":23364563,"url":"https://github.com/tobysolutions/shortener","last_synced_at":"2026-02-11T10:32:44.892Z","repository":{"id":266868704,"uuid":"899608424","full_name":"tobySolutions/shortener","owner":"tobySolutions","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-17T06:41:01.000Z","size":6432,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T08:53:32.175Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://shortener.on-fleek.app","language":"JavaScript","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/tobySolutions.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-12-06T16:10:15.000Z","updated_at":"2024-12-17T06:41:06.000Z","dependencies_parsed_at":"2024-12-06T16:48:02.916Z","dependency_job_id":"dfda9069-d9fe-4946-92e8-5cb8d8fc3038","html_url":"https://github.com/tobySolutions/shortener","commit_stats":null,"previous_names":["tobysolutions/shortener"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobySolutions%2Fshortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobySolutions%2Fshortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobySolutions%2Fshortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobySolutions%2Fshortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobySolutions","download_url":"https://codeload.github.com/tobySolutions/shortener/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247739810,"owners_count":20988084,"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":[],"created_at":"2024-12-21T13:17:00.712Z","updated_at":"2026-02-11T10:32:44.882Z","avatar_url":"https://github.com/tobySolutions.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web3 URL Shortener\n\nA fully decentralized URL-shortening service built with Next.js, Ethereum smart contracts, and Fleek’s edge-optimized hosting. This project demonstrates how to create a censorship-resistant, transparent, and trustless URL shortener on the blockchain, ensuring your shortened links remain accessible and verifiable by anyone.\n\n## Table of Contents\n\n- [Why a Web3 URL Shortener?](#why-a-web3-url-shortener)\n- [Key Benefits](#key-benefits)\n- [Prerequisites](#prerequisites)\n- [Quick Start](#quick-start)\n  - [1. Clone and Install](#1-clone-and-install)\n  - [2. Configure Environment](#2-configure-environment)\n  - [3. Run Local Development Server](#3-run-local-development-server)\n  - [4. Deploy Smart Contract](#4-deploy-smart-contract)\n  - [5. Integration and Edge Deployment (Fleek)](#5-integration-and-edge-deployment-fleek)\n- [Project Structure](#project-structure)\n- [Smart Contract](#smart-contract)\n- [Next.js Integration](#nextjs-integration)\n- [Redirection Flow](#redirection-flow)\n- [Deployment with Fleek](#deployment-with-fleek)\n- [Extending the Project](#extending-the-project)\n- [License](#license)\n\n## Why a Web3 URL Shortener?\n\nTraditional URL shorteners rely on centralized servers, making them vulnerable to censorship, control, and single points of failure. A Web3-driven URL shortener ensures that once you store a link mapping on the blockchain, it’s there permanently and can be accessed without any central authority overriding or censoring the data.\n\n## Key Benefits\n\n- **Decentralization:** URLs are stored on a blockchain, ensuring that no single entity can remove or alter your content.\n- **Censorship Resistance:** Without a central authority, arbitrary censorship becomes impossible.\n- **Transparency:** Anyone can verify link mappings on-chain, ensuring trust and credibility.\n\n## Prerequisites\n\nYou’ll need the following tools and knowledge:\n\n- **Frontend Skills:** Familiarity with React or Next.js.\n- **Node.js \u0026 npm:** Make sure they’re installed on your system.\n- **Fleek Account \u0026 CLI:** Sign up at [Fleek](https://app.fleek.xyz/) and install the [Fleek CLI](https://fleek.xyz/docs/cli/).\n- **Reown Project:** Create a project at [Reown](https://reown.com/).\n- **Test Crypto Wallet:** For contract interactions (e.g. MetaMask).\n- **Web3 Basics:** Understanding of Ethereum smart contracts and blockchain fundamentals.\n\n## Quick Start\n\n### 1. Clone and Install\n\n```bash\ngit clone https://github.com/tobySolutions/shortener.git\ncd shortener\nnpm install\n```\n\n### 2. Configure Environment\n\nCreate a `.env` file in the root directory and populate it with your contract address and RPC URL:\n\n```bash\nNEXT_PUBLIC_CONTRACT_ADDRESS=0x2729D62B3cde6fd2263dF5e3c6509F87C6C05892\nNEXT_PUBLIC_RPC_URL={{YOUR-ARBITRUM-SEPOLIA-RPC-URL}}\n```\n\nBe sure to replace `{{YOUR-ARBITRUM-SEPOLIA-RPC-URL}}` with your actual RPC endpoint.\n\n### 3. Run Local Development Server\n\n```bash\nnpm run dev\n```\n\nVisit [http://localhost:3000](http://localhost:3000) to see the application.\n\n### 4. Deploy Smart Contract\n\nThe included `UrlShortener` contract is deployed on the Arbitrum Sepolia testnet. If you need to deploy your own:\n\n- Compile and deploy using Hardhat or Foundry.\n- Update `NEXT_PUBLIC_CONTRACT_ADDRESS` with your newly deployed contract address.\n- Ensure you have test ETH from the [Arbitrum Sepolia Faucet](https://www.alchemy.com/faucets/arbitrum-sepolia).\n\n### 5. Integration and Edge Deployment (Fleek)\n\n- Log into Fleek:  \n  ```bash\n  fleek login\n  ```\n- Build the project for Fleek:\n  ```bash\n  npx fleek-next build\n  ```\n- Deploy with Fleek:\n  ```bash\n  fleek functions deploy --noBundle --name web3-url-shortener-next-js --path .fleek/dist/index.js --envFile .env\n  ```\n\nAfter deployment, Fleek will provide a URL to access your live, edge-optimized application.\n\n## Project Structure\n\n```\nshortener/\n  ├─ src/\n  │  ├─ pages/\n  │  │  ├─ index.js          # Home page with UI for shortening URLs\n  │  │  ├─ [shortCode].js    # Dynamic route for retrieving/redirecting\n  │  │  └─ _app.js           # Custom app configuration\n  │  ├─ lib/\n  │  │  ├─ contract.js       # Contract instance and helpers\n  │  │  ├─ providers.js      # Web3/Wagmi/RainbowKit providers\n  │  │  ├─ Web3Providers.jsx # Actual provider components (client-only)\n  │  │  └─ URLShortenerApp.jsx # Main client-side logic component\n  │  ├─ abi/\n  │  │  └─ URLShortener.json # Contract ABI\n  │  ├─ styles/\n  │  │  └─ globals.css\n  │  └─ ...\n  ├─ smart-contract/\n  │  ├─ UrlShortener.sol\n  │  └─ ...\n  ├─ .env\n  ├─ tailwind.config.js\n  └─ package.json\n```\n\n## Smart Contract\n\n**UrlShortener.sol**:\n\n```solidity\npragma solidity ^0.8.17;\n\ncontract UrlShortener {\n    mapping(string =\u003e string) private shortToLong;\n    event URLShortened(string indexed shortCode, string longUrl);\n\n    function setURL(string calldata shortCode, string calldata longUrl) external {\n        require(bytes(shortCode).length \u003e 0, \"Short code cannot be empty\");\n        require(bytes(longUrl).length \u003e 0, \"Long URL cannot be empty\");\n        \n        shortToLong[shortCode] = longUrl;\n        emit URLShortened(shortCode, longUrl);\n    }\n\n    function getURL(string calldata shortCode) external view returns (string memory) {\n        return shortToLong[shortCode];\n    }\n}\n```\n\nThis contract maps a short code to a long URL, allowing secure on-chain storage and retrieval.\n\n## Next.js Integration\n\n- **`pages/index.js`**: A UI for users to connect their wallet, provide a short code and a long URL, and submit it to the smart contract.\n- **`[shortCode].js`**: Dynamic Next.js route that resolves the short code by querying the smart contract and then redirects users to the target URL.\n\n## Redirection Flow\n\nWhen a user visits `https://yourdomain.com/abc123`, the `[shortCode].js` page:\n\n1. Fetches the long URL from the contract.\n2. If found, redirects the user to the long URL.\n3. If not found, shows an error page.\n\n## Deployment with Fleek\n\nFleek handles edge deployment, CDN, and serverless functions. Ensure you have the Fleek CLI and run:\n\n```bash\nnpx fleek-next build\nfleek functions deploy --noBundle --name web3-url-shortener-next-js --path .fleek/dist/index.js --envFile .env\n```\n\nThis provides you with a live, immutable URL for your decentralized app.\n\n## Extending the Project\n\n- **Analytics:** Integrate contract events or subgraphs to track usage.\n- **Custom UI/UX:** Enhance design, allow custom short codes, and track click counts.\n- **Multiple Chains:** Expand to multiple EVM-compatible blockchains.\n- **Storage Variations:** Store metadata on IPFS or integrate other decentralized storage solutions.\n\n## License\n\nThis project is provided under the [MIT License](LICENSE).\n\n---\n\n**Original Article:** [Building a Web3 URL Shortener with Next.js on Fleek](https://dev.to/fleek/building-a-web3-url-shortener-with-nextjs-on-fleek-hbb)  \n**Author:** [@tobySolutions](https://github.com/tobySolutions)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobysolutions%2Fshortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobysolutions%2Fshortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobysolutions%2Fshortener/lists"}