Anonymous View
5.1.19 • Published 6 years ago

@parity/light.js v5.1.19

Weekly downloads
56
License
MIT
Repository
github
Last release
6 years ago

@parity/light.js

A high-level reactive JS library optimized for light clients.

Build Status npm (scoped) npm dependencies Status docs

Full Documentation

Getting Started

yarn add @parity/light.js rxjs # RxJS is a needed peer-dependency

Usage

Reactively observe JSONRPC methods:

import light, { defaultAccount$ } from '@parity/light.js';

light.setProvider(/* put your ethereum provider here */);

defaultAccount$().subscribe(publicAddress => console.log(publicAddress));
// Outputs your public address 0x...
// Everytime you change your default account (e.g. via MetaMask), it will output your new public address

All RxJS tools are available for manipulating Observables:

import { balanceOf$, blockNumber$, defaultAccount$ } from '@parity/light.js';
import { filter, map, switchMap } from 'rxjs/operators';

// Only log pair blocks
blockNumber$()
  .pipe(filter(n => n % 2 === 0))
  .subscribe(console.log);

// Get the balance of the default account
// Will update when balance or default account changes
defaultAccount$()
  .pipe(
    switchMap(balanceOf$),
    map(value => +value) // Return number instead of BigNumber
  )
  .subscribe(console.log);

// There's actually an alias for the above Observable:
import { myBalance$ } from '@parity/light.js';
myBalance$().subscribe(console.log);

Contract support:

import { defaultAccount$, makeContract } from '@parity/light.js';
import { map, switchMap } from 'rxjs/operators';

defaultAccount$()
  .pipe(
    switchMap(defaultAccount =>
      makeContract(/* contract address */, /* abi */)
        .myMethod$(defaultAccount) // Calling method of contract with arguments
    )  )
  .subscribe(console.log); // Will log the result, and everytime the result changes

All available methods are documented in the docs.

Usage with React

We provide another library, @parity/light.js-react, with a higher-order component to use these Observables easily with React apps.

import light from 'parity/ligth.js-react';
import { syncStatus$ } from '@parity/light.js';

@light({
  mySyncVariable: syncStatus$
})
class MyClass extends React.Component {
  render() {
    return <div>{JSON.stringify(this.props.mySyncVariable)}</div>;
  }
}

The UI will automatically update when the syncing state changes.

5.1.19

6 years ago

5.1.18

6 years ago

5.1.17

6 years ago

5.1.16

7 years ago

5.1.15

7 years ago

5.1.14

7 years ago

5.1.13

7 years ago

5.1.12

7 years ago

5.1.11

7 years ago

5.1.10

7 years ago

5.1.9

7 years ago

5.1.8

7 years ago

5.1.7

7 years ago

5.1.6

7 years ago

5.1.5

7 years ago

5.1.4

7 years ago

5.1.3

7 years ago

5.1.2

7 years ago

5.1.1

7 years ago

5.1.0

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.31

7 years ago

3.0.30

7 years ago

3.0.29

7 years ago

3.0.28

7 years ago

3.0.27

7 years ago

3.0.26

7 years ago

3.0.25

7 years ago

3.0.24

7 years ago

3.0.23

7 years ago

3.0.22

7 years ago

3.0.21

7 years ago

3.0.19

7 years ago

3.0.18

7 years ago

3.0.13

8 years ago

3.0.12

8 years ago

3.0.11

8 years ago

3.0.10

8 years ago

3.0.9

8 years ago

3.0.8

8 years ago

3.0.7

8 years ago

3.0.6

8 years ago

3.0.5

8 years ago

3.0.4

8 years ago

3.0.3

8 years ago

3.0.1

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago