Nachos Preventing Motivation

    @substrate/connect
    TypeScript icon, indicating that this package has built-in type declarations

    0.4.6 • Public • Published

    Polkadot JS Provider for Smoldot Light Client

    This is a prototype for using @polkadot/api with the smoldot WASM light client either by passing chainspecs or using the extension by predefined chains (e.g. westend, kusama).

    Detector check existence of substrate extension. If it is installed and activated then smoldot clients of extension will be used. If not, a new smoldot client will start and sync with given chainspecs.

    Usage

    Provide a known Chain Name ('kusama', 'polkadot', 'westend', 'rococo'):

    import { Detector } from '@substrate/connect';
    
    const detect = new Detector('my cool unstoppable app');
    
    const api = await detect.connect('westend');

    or provide your custom substrate chain's name and chainspec:

    import { Detector }  from '@substrate/connect';
    import mySubstrateChainSpec from './mySubstrateChainSpec.json';
    
    const chainSpec =  JSON.stringify(mySubstrateChainSpec);
    const detect = new Detector('my cool unstoppable app');
    
    const api = await detect.connect({ name: 'mySubstrateChainName', spec: chainSpec });

    Parachain support

    For parachain support, you can providethe parachain's specs

    import { Detector } from '@substrate/connect';
    import myParaChainSpec from './myParaChainSpec.json';
    
    const parachainSpec =  JSON.stringify(myParaChainSpec);
    
    const detect = new Detector('my cool unstoppable app');
    const api = await detect.connect('westend',  parachainSpec);

    Options

    In addition besides substrate chain's name and/or chainspec, a list of options can be passed to Detector, same way as in as passed in @polkadot/api. Without chainspec:

    import { Detector }  from '@substrate/connect';
    
    const detect = new Detector('my cool unstoppable app');
    const options = { /* the options as per polkadot/api */ } as ApiOptions;
    const api = await detect.connect('mySubstrateChainName', undefined, options);

    or with:

    import { Detector }  from '@substrate/connect';
    import mySubstrateChainSpec from './mySubstrateChainSpec.json';
    
    const chainSpec =  JSON.stringify(mySubstrateChainSpec);
    const detect = new Detector('my cool unstoppable app');
    
    const options = { /* the options as per polkadot/api */ } as ApiOptions;
    const api = await detect.connect({ name: 'mySubstrateChainName', spec: chainSpec }, undefined options);

    Scripts

    • yarn test to run the unit tests
    • yarn build to build @substrate-connect
    • yarn lint to run linter for @substrate-connect

    Keywords

    none

    Install

    npm i @substrate/connect

    DownloadsWeekly Downloads

    1,824

    Version

    0.4.6

    License

    GPL-3.0-only

    Unpacked Size

    14.3 MB

    Total Files

    61

    Last publish

    Collaborators

    • andreieres
    • tomaka
    • goldsteinsveta
    • zekemostov
    • jacogr
    • kianenigma
    • joepetrowski
    • jeluard
    • himurax3x
    • dvdplm
    • wirednkod
    • raoulmillais
    • niklasad1
    • terhix
    • insipx
    • jsdw