|
| 1 | +# Using Lyra Web3 Playground with OpenRouter |
| 2 | + |
| 3 | +Lyra Web3 Playground is an interactive platform for experimenting with Web3 technologies, smart contracts, and AI-assisted development. It supports OpenRouter for AI-powered features. |
| 4 | + |
| 5 | +## What is OpenRouter? |
| 6 | + |
| 7 | +[OpenRouter](https://openrouter.ai) provides access to 200+ AI models through a unified API. |
| 8 | + |
| 9 | +## Setup |
| 10 | + |
| 11 | +### 1. Get Your OpenRouter API Key |
| 12 | + |
| 13 | +1. Sign up at [openrouter.ai](https://openrouter.ai) |
| 14 | +2. Generate an API key at [openrouter.ai/settings/keys](https://openrouter.ai/settings/keys) |
| 15 | + |
| 16 | +### 2. Configure Environment |
| 17 | + |
| 18 | +```bash |
| 19 | +# Server-side |
| 20 | +export OPENROUTER_API_KEY=sk-or-v1-your-key-here |
| 21 | +export OPENROUTER_MODEL=anthropic/claude-sonnet-4 |
| 22 | + |
| 23 | +# Client-side (Vite) |
| 24 | +VITE_OPENROUTER_API_KEY=sk-or-v1-your-key-here |
| 25 | +``` |
| 26 | + |
| 27 | +### 3. Run |
| 28 | + |
| 29 | +```bash |
| 30 | +npm install |
| 31 | +npm run dev |
| 32 | +``` |
| 33 | + |
| 34 | +## AI Features |
| 35 | + |
| 36 | +With OpenRouter configured: |
| 37 | + |
| 38 | +| Feature | Description | |
| 39 | +|---------|-------------| |
| 40 | +| **Contract Generation** | AI-generated Solidity contracts | |
| 41 | +| **Code Explanation** | Understand smart contract code | |
| 42 | +| **Test Generation** | Auto-generate contract tests | |
| 43 | +| **Security Analysis** | AI-powered vulnerability detection | |
| 44 | + |
| 45 | +## Example Usage |
| 46 | + |
| 47 | +### Generate a Smart Contract |
| 48 | + |
| 49 | +``` |
| 50 | +Prompt: "Create an ERC-20 token with minting and burning" |
| 51 | +``` |
| 52 | + |
| 53 | +The AI will generate a complete, audited Solidity contract using your chosen OpenRouter model. |
| 54 | + |
| 55 | +### Explain Code |
| 56 | + |
| 57 | +``` |
| 58 | +Prompt: "Explain what this reentrancy guard does" |
| 59 | +``` |
| 60 | + |
| 61 | +Get detailed explanations of any smart contract code. |
| 62 | + |
| 63 | +## Provider Priority |
| 64 | + |
| 65 | +``` |
| 66 | +OpenRouter → OpenAI |
| 67 | +``` |
| 68 | + |
| 69 | +When `OPENROUTER_API_KEY` is set, it takes priority over direct OpenAI. |
| 70 | + |
| 71 | +## Recommended Models |
| 72 | + |
| 73 | +| Model | Use Case | |
| 74 | +|-------|----------| |
| 75 | +| `anthropic/claude-sonnet-4` | Complex contracts | |
| 76 | +| `openai/gpt-4o` | General development | |
| 77 | +| `deepseek/deepseek-coder` | Code-focused tasks | |
| 78 | + |
| 79 | +## Self-Hosting |
| 80 | + |
| 81 | +```bash |
| 82 | +git clone https://github.com/nirholas/lyra-web3-playground |
| 83 | +cd lyra-web3-playground |
| 84 | +npm install |
| 85 | +echo "OPENROUTER_API_KEY=sk-or-v1-..." > .env |
| 86 | +npm run build && npm start |
| 87 | +``` |
| 88 | + |
| 89 | +## Resources |
| 90 | + |
| 91 | +- [GitHub](https://github.com/nirholas/lyra-web3-playground) |
| 92 | +- [Live Demo](https://playground.lyra.finance) |
| 93 | +- [OpenRouter Docs](https://openrouter.ai/docs) |
0 commit comments