Make a Storage Deal View Source



Here is a partial example of using Textile's Powergate to make a data storage deal. This example only provides an example for how to send your file to a server.

There will be an example of how to make a storage deal coming soon.





Code



0
import * as React from "react";
1
import { CreateFilecoinStorageDeal } from "slate-react-system";
2
import { createPow } from "@textile/powergate-client";
3
4
const PowerGate = createPow({ host: "https://grpcweb.slate.textile.io" });
5
6
class Example extends React.Component {
7
  componentDidMount = async () => {
8
    const FFS = await PowerGate.ffs.create();
9
    const token = FFS.token ? FFS.token : null;
10
    PowerGate.setToken(token);
11
    this.setState({ token });
12
  };
13
14
  _handleSubmit = async (data) => {
15
    const file = data.file.files[0];
16
17
    var buffer = [];
18
19
    // NOTE(jim): A little hacky...
20
    const getByteArray = async () =>
21
      new Promise((resolve) => {
22
        const reader = new FileReader();
23
24
        reader.onloadend = function (e) {
25
          if (e.target.readyState == FileReader.DONE) {
26
            buffer = new Uint8Array(e.target.result);
27
          }
28
29
          resolve();
30
        };
31
32
        reader.readAsArrayBuffer(file);
33
      });
34
35
    await getByteArray();
36
37
    const { cid } = await PowerGate.ffs.stage(buffer);
38
    const { jobId } = await PowerGate.ffs.pushStorageConfig(cid);
39
    const cancel = PowerGate.ffs.watchJobs((job) => {
40
      console.log(job);
41
    }, jobId);
42
  };
43
44
  render() {
45
    return <CreateFilecoinStorageDeal onSubmit={this._handleSubmit} />;
46
  }
47
}
48
ExperiencesCreateFilecoinAddressCreateFilecoinStorageDealCreateTokenFilecoinBalancesListFilecoinDealsListFilecoinSettingsFriendsListPeersListSendAddressFilecoin

Components
Avatar GroupButtonsCard TabsCarouselCheckboxesColorsDatepickerDropdownsGlobeHover TileIconsInputsLine ChartList EditorLoadersModalsNotificationsRadiosSlidersStatsTablesTabsTogglesTooltipsTypography
View source