# graphite-lib

> A library for working with the Graphite cryptocurrency.

Latest version **0.1.0** (published 2022-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphite-lib
pnpm add graphite-lib
yarn add graphite-lib
bun add graphite-lib
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-10-20 |
| First published | 2022-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 7.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | devgraphite |
| Keywords | graphite, crypto, wallet, client-side, web |

## Links

- npm: https://www.npmjs.com/package/graphite-lib
- npm.io page: https://npm.io/package/graphite-lib

## Dependencies (4)

- [web3](https://npm.io/package/web3.md) ^1.7.3
- [bip39](https://npm.io/package/bip39.md) ^3.0.4
- [hdkey](https://npm.io/package/hdkey.md) ^2.0.1
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^7.1.5

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-10-20
- 0.0.1 — 2022-10-20

## README

# graphite-lib

A library for working with the Graphite cryptocurrency.

## Installation

``` console
npm install graphite-lib
# or
yarn add graphite-lib
```

## Supported Environments

- Node.js >= v16.15.0
- npm >= 8.5.0
- yarn >= 1.15.0

## Getting Started

The library allows you to create a new wallet or import a wallet from a mnemonic/private key.

```js
import {Wallet, utils, FeeContract, FilterContract, KycContract} from 'graphite-lib'
```

To create a new Wallet you need to call `createRandom` method. Default word count for new wallet is 15 words.

```js
import {Wallet} from 'graphite-lib'

const wallet = new Wallet()
const wordCount = 21
wallet.createRandom(wordCount) // Takes values equal to 12, 15, 18, 21 or 24
// => {
//   mnemonic: 'new mnemonic ...',
//   address: '0xAE9E7967Dc4...',
//   privateKey: '0x8eee191b5824...',
//   publicKey: 'f9588986d85ad35da07228acd...',
//   provider // web3 provider
// }
```
You can connect to your own node using method `.connect()`. Only non-anonymous nodes are allowed.

```js
const nodeUrl = 'http://...'
wallet.connect(nodeUrl)
```

You can also import a wallet from a mnemonic or a Graphite private key.

```js
const wallet = new Wallet()
const mnemonic = 'kite pencil ...'
wallet.fromMnemonic(mnemonic)

// or

const privateKey = '0x8eee191b5824eb9f...'
wallet.fromPrivateKey(privateKey)
```

## Sending transaction

```js
const nonce = await wallet.provider.getTransactionCount(wallet.address)
const rawTx = await wallet.signTransaction({
  to: '0x5e2FE9Fda4cd5F6F...',
  gasLimit: 300000,
  gasPrice: 20000000000,
  value: 10000000000000000000,
  nonce
})
// => '0xf8840a8504a817c800830493e0945e2fe9fda4cd5f6f...'

const tx = await wallet.sendTransaction(rawTx)
// => {
//   blockHash: "0x715367917e04967dafbf7c54b60f...",
//   blockNumber: 4718,
//   transactionHash: "0x2e964c31fe21f55cb3ef8d7599...",
//   ...
// }

// or you can use .signAndSendTransaction() method instead

const tx = await wallet.signAndSendTransaction({
  to: '0x5e2FE9Fda4cd5F6F...',
  gasLimit: 300000,
  gasPrice: 20000000000,
  value: 10000000000000000000,
  nonce
})
```

## Provider

When creating a class, you will be given a provider to access the network. Ours is based on the commonly known web3js provider component.
    
```js
const wallet = new Wallet()

await wallet.provider.getBlockNumber() // => 4718
await wallet.provider.getGasPrice() // => '20000000000'
```

## Contracts

The wallet provides access to Graphite contracts. To create contracts, call method `.createContracts()`

```js
wallet.createContracts()
// wallet.feeContract - Contract for account activation
// wallet.filterContract - Contract for managing account filters
// wallet.kycContract - Contract for managing KYC levels
```

### Account activation

The wallet must have sufficient funds to activate the account. Gas limit for account activation is 300000 Gwei.

```js
const status = await wallet.getActivationStatus()
// > false - account is not activated
//   true - account is activated

const tx = await wallet.activateAccount()
// Will return the transaction upon successful activation
```

### Filters

To get the current filter level, use `.getFilterLevel()`.

```js
const level = await wallet.getFilterLevel()
// > 0
```

To change the filter level, use `.updateFilterLevel(newLevel)`
```js
const tx = await wallet.updateFilterLevel(1)
```

### KYC

To get the current KYC level, use `.getKycLevel()`.
```js
const level = await wallet.getKycLevel()
// > 0
```

To change the KYC level, use `.updateKycLevel(newLevel)`

```js
const tx = await wallet.updateKycLevel(1)
```

To get the last KYC request, call the method `.viewMyLastKycRequest()`
```js
const lastRequest = await wallet.viewMyLastKycRequest()
```

## Re-Exports

- [web3 utils](https://github.com/ChainSafe/web3.js)

## Tests

```console
$ npm run test
```

## Dev installation

Download the `graphite-lib` repository. Type the following commands into the command prompt:

```console
$ cd graphite-lib
$ npm i
$ npm run build
$ npm link 
```

Go to a chosen project and add the graphite-lib as a local dependency:

```console
$ cd another-project
$ npm link 'graphite-lib'
```

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