fix: use new apis

This commit is contained in:
Vasco Santos 2020-07-07 19:17:42 +02:00
parent 1eaf7619a7
commit a319b5e2e5
3 changed files with 10 additions and 4 deletions

View File

@ -36,7 +36,7 @@ This should open your browser to http://localhost:3000. If it does not, go ahead
### Finding Content via the Delegate
1. Add a file to your IPFS node. From this example root you can do `ipfs add ./README.md` to add the example readme.
2. Copy the hash from line 5, it will look something like *Qmf33vz4HJFkqgH7XPP1uA6atYKTX1BWQEQthzpKcAdeyZ*.
2. Copy the hash from line 5, it will look something like *QmV8QZ1m4fi57fbmaYDAkaTSTjHZVLUJmsqvaP6EcUyUNb*.
3. In the browser, paste the hash into the *Hash* field and hit `Find`. The readme contents should display.
This will do a few things:

View File

@ -12,6 +12,7 @@
"libp2p-secio": "~0.12.5",
"libp2p-webrtc-star": "~0.18.6",
"libp2p-websockets": "~0.13.6",
"peer-id": "^0.13.13",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "^3.2.0"

View File

@ -4,6 +4,7 @@
import React from 'react'
import Ipfs from 'ipfs'
import libp2pConfig from './libp2p-configuration'
import PeerId from 'peer-id'
const BootstrapNode = '/ip4/127.0.0.1/tcp/4010/ws/p2p/QmZrsjJ7v9QoJNjDJmjsQ8947wiK3UnaPPLQvrTSRDAZ2d'
@ -43,10 +44,13 @@ class App extends React.Component {
isLoading: this.state.isLoading + 1
})
const data = await this.ipfs.cat(this.state.hash)
const chunks = []
for await (const chunk of this.ipfs.cat(this.state.hash)) {
chunks.push(chunk)
}
this.setState({
response: data.toString(),
response: Buffer.concat(chunks).toString(),
isLoading: this.state.isLoading - 1
})
}
@ -56,7 +60,8 @@ class App extends React.Component {
isLoading: this.state.isLoading + 1
})
const results = await this.ipfs.dht.findpeer(this.state.peer)
const peerId = PeerId.createFromB58String(this.state.peer)
const results = await this.ipfs.libp2p.peerRouting.findPeer(peerId)
this.setState({
response: JSON.stringify(results, null, 2),