Bootstrap

This commit is contained in:
Franck Royer 2021-07-28 12:37:05 +10:00
parent 2ae9a6ca00
commit 3f6497634f
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 28 additions and 8 deletions

View File

@ -1,24 +1,25 @@
import './App.css';
import { Waku } from 'js-waku';
import { getStatusFleetNodes, Waku } from 'js-waku';
import * as React from 'react';
function App() {
const [waku, setWaku] = React.useState(undefined);
const [wakuStarting, setWakuStarting] = React.useState(false);
const [wakuStatus, setWakuStatus] = React.useState('NotStarted');
React.useEffect(() => {
if (!!waku) return;
if (wakuStarting) return;
if (wakuStatus !== 'NotStarted') return;
setWakuStarting(true);
setWakuStatus('Starting');
Waku.create().then((waku) => {
setWaku(waku);
setWakuStarting(false);
setWakuStatus('Connecting');
bootstrapWaku(waku).then(() => {
setWakuStatus('Ready');
});
});
}, [waku, wakuStarting]);
const wakuStatus = !!waku ? 'Started' : wakuStarting ? 'Loading' : 'Error';
}, [waku, wakuStatus]);
return (
<div className="App">
@ -30,3 +31,8 @@ function App() {
}
export default App;
async function bootstrapWaku(waku) {
const nodes = await getStatusFleetNodes();
await Promise.all(nodes.map((addr) => waku.dial(addr)));
}

View File

@ -25,3 +25,17 @@ import { Waku } from 'js-waku';
const wakuNode = await Waku.create();
```
# Connect to other peers
The Waku instance needs to connect to other peers to communicate with the network.
You are free to choose any method to bootstrap and DappConnect will ship with new methods in the future.
For now, the easiest way is to connect to Status' Waku fleet:
```js
import { getStatusFleetNodes } from 'js-waku';
const nodes = await getStatusFleetNodes();
await Promise.all(nodes.map((addr) => waku.dial(addr)));
```