# fabric-web3js

> Provide offline transaction proposal and transaction sign function.

Latest version **1.0.55** (published 2020-07-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install fabric-web3js
pnpm add fabric-web3js
yarn add fabric-web3js
bun add fabric-web3js
```

## 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.55 |
| Published | 2020-07-21 |
| First published | 2020-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 167 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mingqi |
| Maintainers | mingqi |

## Links

- npm: https://www.npmjs.com/package/fabric-web3js
- npm.io page: https://npm.io/package/fabric-web3js

## Dependencies (5)

- [util](https://npm.io/package/util.md) ^0.12.3
- [buffer-json](https://npm.io/package/buffer-json.md) ^2.0.0
- [fabric-client](https://npm.io/package/fabric-client.md) 1.4.8
- [fabric-common](https://npm.io/package/fabric-common.md) file:./fabric-common
- [fabric-protos](https://npm.io/package/fabric-protos.md) file:./fabric-protos

## Recent versions

- 1.0.55 (latest) — 2020-07-21
- 1.0.54 — 2020-07-21
- 1.0.53 — 2020-06-30
- 1.0.52 — 2020-06-30
- 1.0.51 — 2020-06-30
- 1.0.50 — 2020-06-30
- 1.0.49 — 2020-06-30
- 1.0.48 — 2020-06-30
- 1.0.47 — 2020-06-30
- 1.0.46 — 2020-06-30
- 1.0.45 — 2020-06-30
- 1.0.44 — 2020-06-30
- 1.0.42 — 2020-06-30
- 1.0.41 — 2020-06-24
- 1.0.36 — 2020-06-04
- … 1 more at https://npm.io/package/fabric-web3js/versions

## README

# Fabric-web3js
Provide offline transaction proposal and transaction sign function.

## install
```shell script
yarn add fabric-web3js

npm install fabric-web3js
```

## Sample 

### 1. Singleton ClientProxy
ClientProxy is the main object used to do most stuff, so firstly get one and the only one instance of it.

Call method - **getInstance** to get the only one instance.
```typescript
import { ClientProxy } from 'fabric-web3js';
// singleton instance
const clientProxy = ClientProxy.getInstance();
```

### 2. Setup Credential Store for ClientProxy Instance
ClientProxy manages keys(private/public) and certificate through credential store.

Call async method - **_initCredentialStores_** to setup credential store.
It takes two string parameters:
- one for KVS
- one for CVS
```typescript
await clientProxy.initCredentialStores(
        '/Users/zhangmingqi/Documents/fabric-ca/store/kvs/',
        '/Users/zhangmingqi/Documents/fabric-ca/store/cvs/',
);
```

### 3. Add user keys and certificate into credential store.
Call asyc method -  **_addUser_** to achieve that.

It requires 4 string parameters:
- identity name/username: unique required
- organization MSP id
- private key 
- certificate

```TypeScript
import * as fs from 'fs';
import { ClientProxy } from 'fabric-web3js';

const pathOfPrivateKeyFile = '...';
const pathOfCertificateFile = '...';

const privateKeyPEM = fs.readFileSync(pathOfPrivateKeyFile).toString();
const certificate = fs.readFileSync(pathOfCertificateFile,).toString();

const user = await clientProxy.addUser('admin04.org2.test.example.com', 'Org3MSP', privateKeyPEM, certificate);
```

### 4. Get user by username
ClientProxy can manage multiple users and username is the only field used to query a user from credential store.

Call method - getUser to get a user from credential store.

```typescript
const user = await clientProxy.getUser('admin04.org2.test.example.com');
```

### 5. Generate unsigned endorsement proposal
Compose a proposal request, then call method - generateUnsignedProposal to achieve that.

```typescript
const proposalRequest: ProposalRequest = {
    fcn: 'invoke',
    args: ['a', 'b', '10'],
    chaincodeId: 'sample',
    channelId: 'mychannel',
};
const unsignedProposal = clientProxy.generateUnsignedProposal(proposalRequest);
```

## API
### **initCredentialStores**

### **addUser**

### **getUser**

### **generateUnsignedProposal**

### **generateUnsignedTXPayload**

### **sign**

### **generateSignedProposal**

### **generateSignedTXPayload**

## License
MIT

## Keywords
**fabric** **offline** **sign** **proposal** **transaction** **client** **signature**

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