Created
July 18, 2023 08:59
-
-
Save fend25/bcff059ad868f95480c306c7d6ddc87e to your computer and use it in GitHub Desktop.
substrate connect light node example connecting to parachain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {ApiPromise} from '@polkadot/api' | |
| import {ScProvider} from '@polkadot/rpc-provider' | |
| import * as Sc from '@substrate/connect' | |
| import jsonParachainSpec from './unique_chain_spec.json' | |
| const parachainSpec = JSON.stringify(jsonParachainSpec) | |
| const relayProvider = new ScProvider(Sc, Sc.WellKnownChain.polkadot) | |
| const provider = new ScProvider(Sc, parachainSpec, relayProvider) | |
| console.time('connect') | |
| await provider.connect() | |
| console.timeLog('connect', 'provider connected') | |
| const polkadotApi = await ApiPromise.create({provider}) | |
| console.timeEnd('connect') | |
| await polkadotApi.rpc.chain.subscribeNewHeads((lastHeader) => { | |
| console.log(lastHeader.number.toString()) | |
| }) | |
| await polkadotApi.disconnect() |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "UNIQUE", | |
| "id": "unq", | |
| "chainType": "Live", | |
| "bootNodes": [ | |
| "/dns/p2p-asia-gateway.unique.network/tcp/30333/ws/p2p/12D3KooWLwR4WUEj1AUaqSZcDanpiikS9F8JYZLFotGuVvxkHAvx", | |
| "/dns/p2p-us-gateway.unique.network/tcp/30333/ws/p2p/12D3KooWPK3CLeaKp5cdxXZts55H2P3jPHnxHaT4KFXwY4hWZ4rq", | |
| "/dns/p2p-eu-gateway.unique.network/tcp/30333/ws/p2p/12D3KooWDc1pBNFa4Sc3xeivC9TojdkBRKkSkMFW1VtLCmutq812" | |
| ], | |
| "telemetryEndpoints": null, | |
| "protocolId": "unq", | |
| "properties": { | |
| "ss58Format": 7391, | |
| "tokenDecimals": 18, | |
| "tokenSymbol": "UNQ" | |
| }, | |
| "relay_chain": "polkadot", | |
| "para_id": 2037, | |
| "consensusEngine": null, | |
| "codeSubstitutes": {}, | |
| "genesis": { | |
| "raw": { | |
| "top": { | |
| "0x0342c10eca6b183f939c72ea0a5b603f4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", | |
| "0x0d715f2646c8f85767b5d2764bb2782604a74d81251e398fd8a0a4d55023bb3f": "0xf5070000", | |
| "0x0d715f2646c8f85767b5d2764bb278264e7b9012096b41c4eb3aaf947f6ea429": "0x0000", | |
| "0x1da53b775b270400e7e61ed5cbc5a1464e7b9012096b41c4eb3aaf947f6ea429": "0x0000", | |
| "0x2013754dd003840aea66b349f8241e254e7b9012096b41c4eb3aaf947f6ea429": "0x0000", | |
| "0x2013754dd003840aea66b349f8241e2582fbce236236c63b34351052f96f6751": "0x00", | |
| "0x2013754dd003840aea66b349f8241e25a44704b568d21667356a5a050c118746f52c63705dbee9f60000000000000000000000000000000000000000000000000000000000000000": "0x5b9bd81aae082b2fd8eb489fd8ff19ad0b0b445ca22311be4798d093bd25601c", | |
| "0x2013754dd003840aea66b349f8241e25b1ef0b108928f2a3c149728bbd19fb48": "0x00", | |
| "0x2013754dd003840aea66b349f8241e25c8c156f8164e0465c74b8972ea68b4b3": "0x00000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934700000000000000000000000000000000000000003e71a08250174f712af3cced452c3c218bcc7a44c8c6c1a8baab8ae22a8f688556e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b42156e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060343c02000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
| "0x26aa394eea5630e07c48ae0c9558cef74e7b9012096b41c4eb3aaf947f6ea429": "0x0000", | |
| "0x26aa394eea5630e07c48ae0c9558cef75684a022a34dd8bfa2baaf44f172b710": "0x01", | |
| "0x26aa394eea5630e07c48ae0c9558cef78a42f33323cb5ced3b44dd825fda9fcc": "0x4545454545454545454545454545454545454545454545454545454545454545", | |
| "0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746b4def25cfda6ef3a00000000": "0x4545454545454545454545454545454545454545454545454545454545454545", | |
| "0x26aa394eea5630e07c48ae0c9558cef7a7fd6c28836b9a28522dc924110cf439": "0x01", | |
| "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da99a5aa79001ad7fd14088b574a18e49190ea4c0330527235090286f906763f5dce6ee76cb8d91916185e0e071dce7356d": "0x00000000000000000100000000000000000064a7b3b6e00d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
| "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da99d08bd30ad4eeb88e4546ec948d96dca76ba85214d9ee32ca87269d07f7da8ff39345b262021dfdffacc537c965ce77b": "0x00000000000000000100000000000000000064a7b3b6e00d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
| "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9b993e2010ef972681f7de6d809859ea7a4c72354a402032fb072d8a68e7c12a2953506c757a326e27160d8f553b8bc1d": "0x00000000000000000100000000000000000064a7b3b6e00d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
| "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9ec75332bf4d160041b7eff73b2030d0c36015d3ca0a4dd6f156f81d6eaee34275222913fafbd4179f1a4c418b5290e43": "0x000000000000000001000000000000000000d4aad2a82cf2c1d3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", | |
| "0x26aa394eea5630e07c48ae0c9558cef7f9cce9c888469bb1a0dceaa129672ef8": "0x32f8370018756e69717565", | |
| "0x3a63": "0x", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment