npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electra-js

v0.21.3

Published

Javascript API middleware allowing clients to interact with Electra blockchain.

Downloads

58

Readme

Electra JS

Javascript API allowing clients to interact with Electra blockchain.

The MIT License npm Travis David David

NSP Status Known Vulnerabilities

Getting Started

Install

npm i electra-js

Light Wallet VS Hard Wallet

The hard wallet version (const electraJs = new ElectraJs({ hard: true })) requires a NodeJS-like environment to be executed. The hard wallet utilizes the Electra code binary daemon to interact with the blockchain.

The light wallet version (const electraJs = new ElectraJs()) requires a Browser-like environment to be executed. The light wallet utilizes public web-services to interact with the blockchain.

Examples

States

The wallet can bear 2 states: EMPTY or READY. It will always start as EMPTY once intanciated.

The first wallet method that MUST be called in any case is electraJs.wallet.generate() (described afterwards).

API

Note <parameter> is a mandatory parameter. [parameter] is an optional parameter.

Wallet

Getters:

wallet.addresses

List of the wallet HD addresses.

Response:

Array<{
  hash: string
  isCiphered: boolean
  isHD: boolean
  label: string
  privateKey: string
}>

wallet.allAddresses

List of the wallet non-HD (random) and HD addresses.

Response:

Array<{
  hash: string
  isCiphered: boolean
  isHD: boolean
  label: string
  privateKey: string
}>

wallet.isHD

Is this a HD wallet ?

Response:

boolean

wallet.lockState

Is this wallet locked ? In the case of a light wallet, "STAKING" state can't happen.

Response:

enum {
  LOCKED = 'LOCKED',
  STAKING = 'STAKING',
  UNLOCKED = 'UNLOCKED'
}

wallet.mnemonic

Wallet HD Mnenonic. ONLY available when generating a brand new Wallet, which happens after calling #generate() with an undefined parameter on a Wallet instance with an "EMPTY" #state.

Response:

string

wallet.randomAddresses

List of the wallet non-HD (random) addresses.

Response:

Array<{
  hash: string
  isCiphered: boolean
  isHD: boolean
  label: string
  privateKey: string
}>

wallet.state

Wallet current state.

Response:

enum {
  EMPTY = 'EMPTY',
  READY = 'READY'
}

wallet.transactions

List of the wallet transactions.

Response:

Array<{
  amount: number
  date: number // Unix timestamp in seconds
  fromAddressHash: string
  hash: string
  toAddressHash: string
}>

Methods:

wallet.export([unsafe])

Export wallet data with ciphered private keys, or unciphered if is set to TRUE.

See EIP-0001.

Parameters:

<unsafe>    boolean Export the wallet with its private keys deciphered if TRUE. Optional. Default to FALSE.

Response:

[
  VERSION_INTEGER,
  CHAINS_COUNT_INTEGER,
  HIERARCHICAL_DETERMINISTIC_MASTER_NODE_PRIVATE_KEY_STRING,
  RANDOM_ADDRESSES_PRIVATE_KEYS_STRING_ARRAY
]

wallet.generate([mnemonic], [mnemonicExtension], [chainsCount])

Generate an HD wallet from either the provided mnemonic seed, or a randomly generated one, including ‒ at least ‒ the first derived chain address. In case the [mnemonicExtension] is specified, it MUST be encoded in UTF-8 using NFKD. The method can only be called when the wallet #state is 'EMPTY' and will set its #state to 'READY' if successful.

Parameters:

[mnemonic]          string  The 12 words mnemomic. Optional.
                            A new one will be generated and accessible via #mnemonic getter if not provided.
[mnemonicExtension] string  The mnemonic extension. Optional.
[chainsCount]       number  Number of chain addresses already generated. Optional. Default to 1.

Response:

Promise<void>

wallet.getBalance([addressHash])

Get the global wallet balance, or the balance if specified.

Parameters:

[addressHash]   string  A wallet chain or random address hash. Optional.

Response:

Promise<number>

wallet.lock(<passphrase>, [forStakingOnly])

Lock the wallet, that is cipher all its private keys.

Parameters:

<passphrase>        string  Wallet encryption passphrase.
[forStakingOnly]    boolean Optional. Default to TRUE.

Response:

Promise<void>

wallet.reset()

Reset the current wallet properties and switch the #state to "EMPTY".

Parameters:

N/A

Response:

void

wallet.send(<amount>, <toAddressHash>)

Create and broadcast a new transaction of .

Parameters:

<amount>        number  Amount, in ECA.
<toAddressHash> string  Recipient address hash.

Response:

Promise<void>

wallet.unlock(<passphrase>)

Unlock the wallet, that is decipher all its private keys.

Parameters:

<passphrase>    string  Wallet encryption passphrase.

Response:

Promise<void>

Web Services

webServices.getCurrentPriceIn([currency])

Get the current price of ECA via CoinMarketCap.

Parameters:

[currency] string    One of: 'AUD', 'BRL', 'CAD', 'CHF', 'CLP', 'CNY', 'CZK', 'DKK', 'EUR', 'GBP',
                             'HKD', 'HUF', 'IDR', 'ILS', 'INR', 'JPY', 'KRW', 'MXN', 'MYR', 'NOK',
                             'NZD', 'PHP', 'PKR', 'PLN', 'RUB', 'SEK', 'SGD', 'THB', 'TRY', 'TWD',
                             'USD', 'ZAR'
                     Optional. Default to 'USD'.

Response:

number

Contribute

Getting Started

git clone https://github.com/Electra-project/electra-js.git
cd electra-js
npm i

Start developping

Once you're all set up, you can start coding.

npm start

will automatically start a "live" watch :

  • compiling the JS code (in build folder),
  • checking the lint & typings validation.

Files Structure

├ build                 Development release
├ dist                  Production release (the one distributed via npm)
│ ├ index.d.ts            - Types declarations for clients written in Typescript
│ └ index.js              - Main bundle
├ node_modules          Dependencies local installation directory
├ src                   The main directory
├ tasks                 Specific tasks run via the npm scripts
├ test                  Production release main bundle checkings (import/require tests)
│ ├ browser               - Browser compatibility tests (tested via Selenium WebDriver)
│ │ ├ index.html            - HTML container served by Express
│ │ ├ index.spec.js         - Tests suite run within the browser
│ │ └ index.ts              - CLI browser tests runner (checking for browser errors)
│ ├ index.js              - Javascript checkings
│ └ index.ts              - Typescript checkings
├ .editorconfig         Common IDE and Editors configuration
├ .gitignore            Files and directories ignored by Git
├ .npmignore            Files and directories ignored in the npm published package
├ .npmrc                The npm workspace options
├ .travis.yml           Travis CI automated tests configuration
├ LICENSE               License
├ package-lock.json     Accurately versionned list of the npm dependencies tree
├ package.json          The npm configuration
├ README.md             The current file
├ tsconfig.json         Typescript configuration (tsc options)
├ tslint.json           TSLint configuration
├ webpack.common.js     Common Webpack configuration
├ webpack.dev.js        Webpack development configuration
└ webpack.prod.js       Webpack production configuration

Release a new version

1/3 Prepare the release

npm version [minor|patch]

It will automatically :

  1. Run the tests (including the typings & lint validation).
  2. Build the production release artifacts: dist/index.js & dist/index.d.ts.
  3. Upgrade the version in package.json (npm job).
  4. Upgrade the version in dist/index.js.
  5. Run the artifacts checkings.
  6. Add the release files to Git.
  7. Commit the files with the message X.Y.Z matching the new version (npm job).

2/3 Push the release

git push origin HEAD

You then need to wait for Travis CI tests to pass.

3/3 Publish the release

npm publish