1.0.0 • Published 9 months ago

@spheron/fvm-deal-utils v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

getFvmMetadata Example

In the example below you can see how to create an instance of SpheronDealClient and how to generate the metadata required for creating a storage deal on FVM.

const {
  SpheronDealClient,
  DealDataResult,
} = require("@spheron/fvm-deal-utils");

const client = new SpheronDealClient({ token });

let currentlyUploaded = 0;
const result: DealDataResult = await client.getFvmMetadata(filePath, {
  name,
  onUploadInitiated: (uploadId) => {
    console.log(`Upload with id ${uploadId} started...`);
  },
  onChunkUploaded: (uploadedSize, totalSize) => {
    currentlyUploaded += uploadedSize;
    console.log(`Uploaded ${currentlyUploaded} of ${totalSize} Bytes.`);
  },
});
  • The response of the getFvmMetadata function is an object with the following properties:
    • pieceSize - the size of the file in bytes
    • size - the size of the CAR file in bytes
    • pieceCid - hash of the piece in hex
    • dataCid - IPFS hash of the car file
    • carLink - the IPFS URL of the generated car file.
    • carName - the name of the car
    • uploadId - the id of the upload on which the car was uploaded

Access Token

To create the token that is used with the SpheronClient, follow the instructions in the DOCS. When you are creating the tokens, please choose web app type in the dashboard.

Notes

The package is only meant for Node.js environments and will not work in a browser or frontend apps.

Learn More

You can learn more about Spheron and Storage SDK here: