# @moibitjs/matic

> MoiBit module which writes provenance to matic network

Latest version **1.0.1** (published 2020-12-07) · 0 weekly downloads

## Install

```sh
npm install @moibitjs/matic
pnpm add @moibitjs/matic
yarn add @moibitjs/matic
bun add @moibitjs/matic
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-12-07 |
| First published | 2019-10-22 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 45.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | its-VSP |
| Maintainers | its_vsp, aicumen |
| Keywords | on-chain, matic, storage, moibit, provenance, sdk, js, files |

## Links

- npm: https://www.npmjs.com/package/@moibitjs/matic
- Repository: https://github.com/moibit/matic
- Homepage: https://github.com/moibit/matic#readme
- Issues: https://github.com/moibit/matic/issues
- npm.io page: https://npm.io/package/@moibitjs/matic

## Dependencies (2)

- [keccak256](https://npm.io/package/keccak256.md) ^1.0.0
- [@moibitjs/core](https://npm.io/package/@moibitjs/core.md) ^1.1.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-12-07
- 1.0.0 — 2019-10-24
- 0.1.1 — 2019-10-22
- 0.1.0 — 2019-10-22

## README

![MoiBit + Matic](https://raw.githubusercontent.com/moibit/logo-assets/master/partnerships/moibit%2Bmatic.png)

# @moibitjs/matic

[![npm version](https://badge.fury.io/js/%40moibitjs%2Fmatic.svg)](https://badge.fury.io/js/%40moibitjs%2Fmatic)
[![Chat on Slack](https://img.shields.io/badge/Slack-MoiBit%20Slack%20community-blue)](https://join.slack.com/t/moibit/signup)
[![Chat on Telegram](https://img.shields.io/badge/Telegram-MoiBit%20Telegram%20community-blue)](https://t.me/moibit)
[![Follow us on Twitter](https://img.shields.io/badge/Twitter-MoiBit%20Twitter-blue?style=social&logo=twitter)](https://twitter.com/moibitio)

**MoiBitJS/matic** uses [MoiBitJS/core module](https://github.com/moibit/core) to perform file actions and the provenance of files will be stored in [Matic network](https://matic.network).

## Installation

Just run the following npm command and the SDK will be installed.
``` bash
npm install --save @moibitjs/matic
```

## Get Started

``` js
import  Matic  from  'maticjs'
import  MoiBit  from  '@moibitjs/matic'
// Initialize matic object
let _matic = new Matic({
	parentProvider : 'https://ropsten.infura.io/v3/70645f042c3a409599c60f96f6dd9fbc',
	maticProvider : 'https://testnet2.matic.network'
});

// Initialize moibit object with matic object as parameter
let  mFiles = new  MoiBit(_matic)
await  mfiles.init('<your-url>',{
	API_KEY :  '<your-api-key>'
	API_SECRET : '<your-api-secret>'
});

//needs signing of transaction to matic network that stores multihash for provenance, before adding file to moibit
await  mfiles.add(file,'sample.txt')
```

## Functions
### new MoiBit(maticObject)
Bind your matic object to moibit
``` js
var  mFiles = new  MoiBit(maticObject)
```
### mFiles.init(url,accessToken)
Initialize your MoiBit Object with matic. Get your MoiBit account [here](https://account.moibit.io). After signing up you will be getting **_API_KEY , API_SECRET , URL_**

-  <code>url</code> you got after signing up

-  <code>accessToken</code> is a combination of _API_KEY_ and _API_SECRET_

``` js
await  mFiles.init('<your-url>',{
	API_KEY :  '<your-api-key>' ,
	API_SECRET :  '<your-api-secret>'
});
```
### mFiles.add(file,path,options)

Add file of any type which will be stored in MoiBit and the returned multi-hash will be stored in matic chain where you are expected to sign a transaction.
-  <code>file</code> can be window file object or stream
-  <code>path</code> is an absolute path in your files directory at which you want the file to be inserted.
-  <code>options</code>
	-  `createFolders` is a boolean value which specifies to create a folder/not if it is not existing , that was mentioned in above path attribute (_default : true_)
	-  `pinVersion` is a boolean value which tells to pin the file while adding.(_default : false_)

``` js
await  mFiles.add(fileObject,'parent1/folder2/file3.txt');
```

### mFiles.read(path,responseType)

Returns file with specified return type only if the hash stored 
**on-chain (ie., in Matic) and off-chain (ie., in MoiBit) are same**,
 if not returns negative response 
 ``` js
 {
		 validation : failed, 
		 message : 'No record matching <off-chain hash>'
}
```

- `path` is an absolute path

- `responseType` can be anything among

	- _arraybuffer , document , json , text , stream_

	- _blob - browser only_
	
``` js
await  mFiles.read('parent1/folder2/file3.txt','blob');
```
to do more actions other than `add & read` with files module visit [@moibitjs/core](https://github.com/moibit/core)


## Maintainers

1. [Vuppala Sai Prashanth](https://github.com/its-VSP)
2. [Arunprakash](https://github.com/Arunprakash1414)

## Reviewers

1. Ayush Gupta
2. Ganesh Prasad Kumble

## Support

If you need more clarifications, feel free to join our Telegram or Slack community channels. You can also write us an email at [hello@moibit.io](mailto:hello@moibit.io)

## License

[GNU General Public License v3.0](https://github.com/moibit/matic/blob/master/LICENSE)

---
_Source: https://npm.io/package/@moibitjs/matic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
