This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathApp.js
57 lines (55 loc) · 1.51 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict'
const React = require('react')
const ipfsClient = require('ipfs-http-client')
const ipfs = ipfsClient('localhost', '5001')
const stringToUse = 'hello world from webpacked IPFS'
class App extends React.Component {
constructor (props) {
super(props)
this.state = {
id: null,
version: null,
protocol_version: null,
added_file_hash: null,
added_file_contents: null
}
}
componentDidMount () {
ipfs.id((err, res) => {
if (err) throw err
this.setState({
id: res.id,
version: res.agentVersion,
protocol_version: res.protocolVersion
})
})
ipfs.add([Buffer.from(stringToUse)], (err, res) => {
if (err) throw err
const hash = res[0].hash
this.setState({ added_file_hash: hash })
ipfs.cat(hash, (err, data) => {
if (err) throw err
this.setState({ added_file_contents: data.toString() })
})
})
}
render () {
return <div style={{ textAlign: 'center' }}>
<h1>Everything is working!</h1>
<p>Your ID is <strong>{this.state.id}</strong></p>
<p>Your IPFS version is <strong>{this.state.version}</strong></p>
<p>Your IPFS protocol version is <strong>{this.state.protocol_version}</strong></p>
<div>
<div>
Added a file! <br />
{this.state.added_file_hash}
</div>
<div>
Contents of this file: <br />
{this.state.added_file_contents}
</div>
</div>
</div>
}
}
module.exports = App