Package Exports
- graphite-lib
- graphite-lib/dist/graphite-lib.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphite-lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
graphite-lib
A library for working with the Graphite cryptocurrency.
Installation
npm install graphite-lib
# or
yarn add graphite-libSupported 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.
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.
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.
const nodeUrl = 'http://...'
wallet.connect(nodeUrl)You can also import a wallet from a mnemonic or a Graphite private key.
const wallet = new Wallet()
const mnemonic = 'kite pencil ...'
wallet.fromMnemonic(mnemonic)
// or
const privateKey = '0x8eee191b5824eb9f...'
wallet.fromPrivateKey(privateKey)Sending transaction
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.
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()
wallet.createContracts()
// wallet.feeContract - Contract for account activation
// wallet.filterContract - Contract for managing account filters
// wallet.kycContract - Contract for managing KYC levelsAccount activation
The wallet must have sufficient funds to activate the account. Gas limit for account activation is 300000 Gwei.
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 activationFilters
To get the current filter level, use .getFilterLevel().
const level = await wallet.getFilterLevel()
// > 0To change the filter level, use .updateFilterLevel(newLevel)
const tx = await wallet.updateFilterLevel(1)KYC
To get the current KYC level, use .getKycLevel().
const level = await wallet.getKycLevel()
// > 0To change the KYC level, use .updateKycLevel(newLevel)
const tx = await wallet.updateKycLevel(1)To get the last KYC request, call the method .viewMyLastKycRequest()
const lastRequest = await wallet.viewMyLastKycRequest()Re-Exports
Tests
$ npm run testDev installation
Download the graphite-lib repository. Type the following commands into the command prompt:
$ cd graphite-lib
$ npm i
$ npm run build
$ npm link Go to a chosen project and add the graphite-lib as a local dependency:
$ cd another-project
$ npm link 'graphite-lib'