js-mcs-sdk

4.3.0 • Public • Published

Multichain Storage SDK - Javascript

Made by FilSwan Chat on discord

A javascript software development kit for the Multi-Chain Storage (MCS) https://www.multichain.storage/ service. It provides a convenient interface for working with the MCS API from a web browser or Node.js. This SDK has the following functionalities:

Table of Contents

🆕 Getting Started

Prerequisites

Installation

In a new working directory, use npm init -y to initialize a Node.js project. Install the package using npm

npm init -y
npm install js-mcs-sdk

Setup Credentials

Create a .env file that includes the following content. Optionally include your wallet's private key and RPC-url.

API_KEY='<API_KEY>'
ACCESS_TOKEN='<ACCESS_TOKEN>'

# for onchain storage only
PRIVATE_KEY='<PRIVATE_KEY>'
RPC_URL='<RPC_URL>'

Initialize SDK

require('dotenv').config()
const { mcsSDK } = require('js-mcs-sdk')

async function main() {
  // initialize js-mcs-sdk
  const mcs = await mcsSDK.initialize({
    apiKey: process.env.API_KEY,
    accessToken: process.env.ACCESS_TOKEN,
    chainName: 'polygon.mainnet',
  })
}

main()

👨‍💻 Examples

Bucket Storage

  • Create a bucket

    let bucketData = await mcs.createBucket('<BUCKET_NAME>')
    console.log(bucketData)
  • Upload a file to the bucket

    let fileData = mcs.uploadToBucket(
      '<BUCKET_NAME>',
      '<OBJECT_NAME>',
      '<FILE_PATH>',
    )
    console.log(fileData)

For more examples, please see the SDK documentation.

Onchain Storage

Onchain storage is designed for storing file information in the smart contract. It requires payment for each file.

To use certain Onchain Storage features (upload, payment, minting), you will need to set up the web3 environment first.

  • Setup Web3

    await mcs.setupWeb3(process.env.PRIVATE_KEY, process.env.RPC_URL)
    console.log(mcs.web3Initialized) // true
  • Upload File to Onchain storage

    let uploadResponse = await mcs.upload('<FILE_PATH>')
    console.log(uploadResponse)
  • Pay for file storage after uploading, the response should return the source_file_upload_id and the file size.

    let tx = await mcs.makePayment('SOURCE_FILE_UPLOAD_ID>', '<FILE_SIZE>')
    console.log(transaction hash: ' + tx.transactionHash)

ℹ️ Functions

For Onchain Storage


  • POST Upload file to Filswan IPFS gateway
  • GET List of files uploaded
  • GET Files by cid
  • GET Status from filecoin
  • CONTRACT Make payment to swan filecoin storage gateway
  • CONTRACT Mint asset as NFT

For Buckets Storage


  • POST Create a bucket
  • POST Create a folder
  • POST Upload File to the bucket
  • POST Rename bucket
  • GET Delete bucket
  • GET Bucket List
  • GET File List
  • GET File information
  • GET Delete File

🌐 Contributing

Feel free to join in and discuss. Suggestions are welcome! Open an issue or Join the Discord!

Sponsors

Filecoin Foundation sponsors this project

Flink SDK - A data provider offers Chainlink Oracle service for Filecoin Network

Readme

Keywords

none

Package Sidebar

Install

npm i js-mcs-sdk

Weekly Downloads

44

Version

4.3.0

License

ISC

Unpacked Size

53.1 kB

Total Files

17

Last publish

Collaborators

  • swan-ryuen