We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 475acfa commit 5e4ff09Copy full SHA for 5e4ff09
App/scripts/pirate.js
@@ -0,0 +1,22 @@
1
+const IPFS = require('ipfs-api');
2
+const ipfs = IPFS({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' });
3
+
4
+async function uploadData(data) {
5
+ const buffer = Buffer.from(JSON.stringify(data));
6
+ const result = await ipfs.add(buffer);
7
+ console.log('Data uploaded to IPFS:', result[0].hash);
8
+ return result[0].hash;
9
+}
10
11
+async function downloadData(hash) {
12
+ const files = await ipfs.cat(hash);
13
+ const data = JSON.parse(files.toString());
14
+ console.log('Data downloaded from IPFS:', data);
15
+ return data;
16
17
18
+// Example usage:
19
+const data = { x: 10, y: 10, vx: 1, vy: 1 };
20
+uploadData(data).then(hash => {
21
+ downloadData(hash);
22
+});
0 commit comments