Skip to content

Commit 103b9b4

Browse files
committed
Add SolidStart web3 onboarding template
1 parent e3b8623 commit 103b9b4

30 files changed

+922
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generate using `openssl rand -hex 32`
2+
SESSION_SECRET = myverylongsessionsecretkeythatishouldchange
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.data
3+
pnpm-lock.yaml
4+
package-lock.json
5+
.env

examples/with-solidstart/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[![Banner](https://assets.solidjs.com/banner?background=tiles&type=Start&project=template)](https://github.com/solidjs/solid-start)
2+
3+
Kickstart your DeFi app development with this starter template, built with [SolidStart](https://start.solidjs.com) and [Web3Onboard](https://web3onboard.thirdweb.com).
4+
It seamlessly integrates SolidStart’s server-side rendering (_SSR_) with client-side Web3 features, leveraging libraries like [ethers.js](https://github.com/ethers-io/ethers.js).
5+
6+
## Features
7+
8+
- **SSR Compliant**: Web3 code loads only on the client, ensuring compatibility with SSR architecture
9+
- **Auth Context**: A reactive context to monitor wallet changes, handle signatures, and more
10+
- **Local Storage**: Utilizes a lightweight, file-based database with `unstorage` for persistence
11+
- **Starter Kit for DeFi**: Preconfigured setup to kickstart your DeFi app development with SolidStart and Web3Onboard
12+
- **Client-Only**: Easily isolate client-side logic for Web3 interactions
13+
14+
## Getting Started
15+
16+
1. Install dependencies
17+
18+
```bash
19+
# use preferred package manager
20+
npm install
21+
```
22+
23+
2. Run the development server
24+
25+
```bash
26+
# use preferred package manager
27+
npm run dev
28+
```
29+
30+
3. Rename `.env.example` to `.env`. For production, generate a secure `SESSION_SECRET` with
31+
32+
```bash
33+
openssl rand -hex 32
34+
```
35+
36+
## Usage
37+
38+
To ensure Web3-related logic runs only on the client, use the `clientOnly` utility from SolidStart. Here are two ways to implement client-only code:
39+
40+
1. **Client-Only Component** (e.g. for a component showing user balance)
41+
42+
```jsx
43+
import { clientOnly } from "@solidjs/start/client";
44+
45+
const ClientComponent = clientOnly(() => import("./ClientOnlyComponent"));
46+
```
47+
48+
2. **Client-Only Page** (e.g. for a `/swap` page)
49+
Add the following at the top of your route file to render the entire page on the client:
50+
51+
```jsx
52+
import { clientOnly } from "@solidjs/start/client";
53+
54+
export default clientOnly(async () => ({ default: MyPage }));
55+
```
56+
57+
For more details, refer to the `clientOnly` [documentation](https://docs.solidjs.com/solid-start/reference/client/client-only#clientonly).
58+
59+
<div align="center">
60+
</br>
61+
</br>
62+
<img src="public/logo.svg" width="300px">
63+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "@solidjs/start/config";
2+
import tailwindcss from "@tailwindcss/vite";
3+
4+
export default defineConfig({
5+
server: { preset: "" }, // your deployment
6+
vite: { plugins: [tailwindcss()] }
7+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"dev": "vinxi dev --port 3001",
5+
"build": "vinxi build",
6+
"start": "vinxi start",
7+
"format": "prettier --write . --trailing-comma none"
8+
},
9+
"dependencies": {
10+
"@solidjs/meta": "^0.29.4",
11+
"@solidjs/router": "^0.15.3",
12+
"@solidjs/start": "^1.2.0",
13+
"@web3-onboard/core": "^2.24.1",
14+
"@web3-onboard/injected-wallets": "^2.11.3",
15+
"ethers": "^6.15.0",
16+
"solid-js": "^1.9.10",
17+
"unstorage": "1.17.1",
18+
"vinxi": "^0.5.8"
19+
},
20+
"devDependencies": {
21+
"@tailwindcss/vite": "^4.1.16",
22+
"prettier": "^3.6.2",
23+
"tailwindcss": "^4.1.16"
24+
},
25+
"engines": {
26+
"node": ">=22"
27+
}
28+
}
Lines changed: 92 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import "tailwindcss";
2+
3+
#app {
4+
background-color: white;
5+
user-select: none;
6+
@media (scripting: none) {
7+
display: none;
8+
}
9+
}
10+
11+
main {
12+
@apply flex flex-col items-center justify-center min-h-screen bg-gray-50 gap-18 px-4;
13+
}
14+
15+
h1 {
16+
@apply uppercase text-6xl text-sky-700 font-thin;
17+
}
18+
19+
button {
20+
cursor: pointer;
21+
}
22+
23+
.loader {
24+
@apply animate-spin border-current border-t-transparent text-current rounded-full;
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Suspense } from "solid-js";
2+
import { Router, type RouteDefinition } from "@solidjs/router";
3+
import { FileRoutes } from "@solidjs/start/router";
4+
import { MetaProvider } from "@solidjs/meta";
5+
import { querySession } from "./auth";
6+
import AuthProvider from "./auth/Provider";
7+
import Nav from "./components/Nav";
8+
import ErrorNotification from "./components/Error";
9+
import "./app.css";
10+
11+
export const route: RouteDefinition = {
12+
preload: ({ location }) => querySession(location.pathname)
13+
};
14+
15+
export default function App() {
16+
return (
17+
<Router
18+
root={(props) => (
19+
<MetaProvider>
20+
<AuthProvider>
21+
<Suspense>
22+
<Nav />
23+
{props.children}
24+
<ErrorNotification />
25+
</Suspense>
26+
</AuthProvider>
27+
</MetaProvider>
28+
)}
29+
>
30+
<FileRoutes />
31+
</Router>
32+
);
33+
}

0 commit comments

Comments
 (0)