Skip to content

Commit 25fe93a

Browse files
authored
Feat/add solidjs support (#1886)
1 parent 8ddf5e6 commit 25fe93a

File tree

35 files changed

+5558
-9
lines changed

35 files changed

+5558
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ For full documentation, check out the README.md for each package or the [docs pa
136136
**Frameworks**
137137

138138
- [React](packages/react/README.md)
139+
- [Solid](packages/solid/README.md)
139140
- [Vue](packages/vue/README.md)
140141

141142
## Test out the demo app

docs/src/routes/docs/[...1]overview/[...1]introduction/+page.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ We recommend you add the [Core Repo](../../modules/core.md#install) and consider
192192
**Frameworks**
193193

194194
- [React](../../modules/react.md#quickstart-with-injected-wallets-and-ethers-provider)
195+
- [Solid](../../modules/solid.md#install)
195196
- [Vue](../../modules/vue.md#install)
196197

197198
## Test out the demo app

docs/src/routes/docs/[...3]modules/[...1]core/+page.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ npm install @web3-onboard/coinbase @web3-onboard/metamask @web3-onboard/fortmati
8181

8282
- All wallet modules (except for `injected-wallets`) require extra dependencies and may require polyfilling the node built in modules for the browser. See the [Build Environments](#build-environments) section for more info
8383
- **If using React** you may be interested in checking out the React Hooks package here - https://www.npmjs.com/package/@web3-onboard/react
84+
- **If using Solid** you may be interested in checking out the Solid package here - https://www.npmjs.com/package/@web3-onboard/solid
8485
- **If using Vue** you may be interested in checking out the Vue package here - https://www.npmjs.com/package/@web3-onboard/vue
8586
:::
8687

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
---
2+
title: Solid.js
3+
---
4+
5+
# {$frontmatter.title}
6+
7+
A collection of composable functions for implementing web3-onboard in to a Solid project;
8+
9+
## Quickstart with Injected Wallets and Ethers Provider
10+
11+
### Install
12+
13+
<Tabs values={['yarn', 'npm']}>
14+
<TabPanel value="yarn">
15+
16+
```sh copy
17+
yarn add @web3-onboard/solid @web3-onboard/injected-wallets
18+
```
19+
20+
</TabPanel>
21+
<TabPanel value="npm">
22+
23+
```sh copy
24+
npm install @web3-onboard/solid @web3-onboard/injected-wallets
25+
```
26+
27+
</TabPanel>
28+
</Tabs>
29+
30+
31+
## Quickstart
32+
33+
```typescript
34+
import { init } from '@web3-onboard/solid'
35+
import injectedModule from '@web3-onboard/injected-wallets'
36+
37+
const injected = injectedModule()
38+
39+
// Only one RPC endpoint required per chain
40+
const rpcAPIKey = '<INFURA_KEY>' || '<ALCHEMY_KEY>'
41+
const rpcUrl =
42+
`https://eth-mainnet.g.alchemy.com/v2/${rpcAPIKey}` ||
43+
`https://mainnet.infura.io/v3/${rpcAPIKey}`
44+
45+
const web3Onboard = init({
46+
wallets: [injected],
47+
chains: [
48+
{
49+
id: '0x1',
50+
token: 'ETH',
51+
label: 'Ethereum Mainnet',
52+
rpcUrl
53+
},
54+
{
55+
id: '0x2105',
56+
token: 'ETH',
57+
label: 'Base',
58+
rpcUrl: 'https://mainnet.base.org'
59+
}
60+
]
61+
})
62+
63+
const { wallets, connectWallet, disconnectConnectedWallet, connectedWallet } =
64+
useOnboard()
65+
66+
if (connectedWallet) {
67+
// if using ethers v6 this is:
68+
// ethersProvider = new ethers.BrowserProvider(wallet.provider, 'any')
69+
const ethersProvider = new ethers.providers.Web3Provider(
70+
connectedWallet.provider,
71+
'any'
72+
)
73+
// ..... do stuff with the provider
74+
}
75+
```
76+
77+
## Functions
78+
79+
### `init`
80+
81+
The `init` function initializes `web3-onboard` and makes it available to the `useOnboard()` composable. For references check out the [initialization docs for `@web3-onboard/core`](../core/README.md#initialization)
82+
83+
#### Example usage
84+
85+
```typescript
86+
import { init } from '@web3-onboard/solid'
87+
import injectedModule from '@web3-onboard/injected-wallets'
88+
89+
const injected = injectedModule()
90+
const infuraKey = '<INFURA_KEY>'
91+
const rpcUrl = `https://mainnet.infura.io/v3/${infuraKey}`
92+
93+
const web3Onboard = init({
94+
wallets: [injected],
95+
chains: [
96+
{
97+
id: '0x1',
98+
token: 'ETH',
99+
label: 'Ethereum Mainnet',
100+
rpcUrl
101+
}
102+
]
103+
})
104+
```
105+
106+
### `useOnboard`
107+
108+
`useOnboard` must be used after the `init` function has been called - it will return an object that can be destructured to obtain the following reactive variables and functions:
109+
110+
#### Example usage
111+
112+
```typescript
113+
import { useOnboard } from '@web3-onboard/solid'
114+
// Use the composable
115+
const onboard = useOnboard()
116+
// Or destructure it
117+
const {
118+
wallets,
119+
connectedWallet,
120+
connectedChain,
121+
connectWallet,
122+
disconnectConnectedWallet
123+
} = useOnboard()
124+
// do stuff
125+
```
126+
127+
### `connectWallet`
128+
129+
Function to open the onboard modal and connect to a wallet provider. For reference check out the [connecting a wallet for `@web3-onboard/core`](../core/README.md#connecting-a-wallet)
130+
131+
#### Example usage
132+
133+
```tsx
134+
function SampleConnect() {
135+
const { connectWallet } = useOnboard()
136+
137+
return <button onClick={() => connectWallet()}> connect wallet</button>
138+
}
139+
```
140+
141+
### `connectedChain`
142+
143+
Property that contains the current chain to which `connectedChain` is connected
144+
145+
#### Example usage
146+
147+
```tsx
148+
function SampleConnect() {
149+
const { connectedChain } = useOnboard()
150+
151+
return <span>Connected Chain: { connectedChain() }</span>
152+
```
153+
154+
### `connectedWallet`
155+
156+
Property that contains the latest connected wallet
157+
158+
#### Example usage
159+
160+
```tsx
161+
function SampleConnect() {
162+
const { connectedWallet } = useOnboard()
163+
return <span>Connected Wallet: {connectedWallet()?.label}</span>
164+
}
165+
```
166+
167+
### `disconnectConnectedWallet`
168+
169+
Function to disconnect the `connectedWallet`
170+
171+
#### Example usage
172+
173+
```tsx
174+
import { useOnboard } from '@web3-onboard/solid'
175+
function SampleConnect() {
176+
const { disconnectConnectedWallet } = useOnboard()
177+
return (
178+
<button onClick={() => disconnectConnectedWallet()}>
179+
{' '}
180+
disconnect wallet
181+
</button>
182+
)
183+
}
184+
```
185+
186+
### `getChain`
187+
188+
Function that returns the current chain a wallet is connected to
189+
190+
#### Example usage
191+
192+
```tsx
193+
import { useOnboard } from '@web3-onboard/solid'
194+
function SampleConnect() {
195+
const { getChain } = useOnboard()
196+
return <span>MetaMask is connected to: {getChain('MetaMask')}</span>
197+
}
198+
```
199+
200+
### `setChain`
201+
202+
Function to set the chain of a wallet
203+
204+
#### Example usage
205+
206+
```tsx
207+
import { useOnboard } from '@web3-onboard/solid'
208+
function SampleConnect() {
209+
const { setChain } = useOnboard()
210+
const set = () => setChain({ wallet: 'MetaMask', chainId: '0x1' })
211+
return (
212+
<button type="button" onClick={set}>
213+
Set MetaMask chain to mainnet
214+
</button>
215+
)
216+
}
217+
```
218+
219+
### `settingChain`
220+
221+
Readonly boolean ref that tracks the status of setting the chain
222+
223+
#### Example usage
224+
225+
```tsx
226+
import { useOnboard } from '@web3-onboard/solid'
227+
function SampleConnect() {
228+
const { settingChain } = useOnboard()
229+
return { settingChain }
230+
}
231+
```
232+
233+
### `wallets`
234+
235+
Readonly ref that contains every wallet that has been connected
236+
237+
#### Example usage
238+
239+
```tsx
240+
import { useOnboard } from '@web3-onboard/solid'
241+
function SampleConnect() {
242+
const { wallets } = useOnboard()
243+
return(
244+
<ul>
245+
<For each={wallets()}>{wallet=>{
246+
return <li>
247+
{wallet.label}
248+
</li>
249+
}}
250+
</For>
251+
</ul>
252+
)
253+
}
254+
}
255+
```
256+
257+
### `lastConnectedTimestamp`
258+
259+
Readonly ref that contains the last time that the user connected a wallet in milliseconds
260+
261+
#### Example usage
262+
263+
```tsx
264+
import { useOnboard } from '@web3-onboard/solid'
265+
function SampleConnect() {
266+
const { lastConnectedTimestamp } = useOnboard()
267+
return (
268+
<span>Your last connection timestamp was: {lastConnectedTimestamp}</span>
269+
)
270+
}
271+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/with-solidjs/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

examples/with-solidjs/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Usage
2+
3+
```bash
4+
$ npm install # or pnpm install or yarn install
5+
```
6+
7+
### Learn more on the [Solid Website](https://solidjs.com) and come chat with us on our [Discord](https://discord.com/invite/solidjs)
8+
9+
## Available Scripts
10+
11+
In the project directory, you can run:
12+
13+
### `npm run dev`
14+
15+
Runs the app in the development mode.<br>
16+
Open [http://localhost:5173](http://localhost:5173) to view it in the browser.
17+
18+
### `npm run build`
19+
20+
Builds the app for production to the `dist` folder.<br>
21+
It correctly bundles Solid in production mode and optimizes the build for the best performance.
22+
23+
The build is minified and the filenames include the hashes.<br>
24+
Your app is ready to be deployed!
25+
26+
## Deployment
27+
28+
Learn more about deploying your application with the [documentations](https://vitejs.dev/guide/static-deploy.html)

examples/with-solidjs/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + Solid</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/index.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)