11import * as smoldot from 'smoldot' ;
2- import fs from 'fs' ;
2+ import { cryptoWaitReady } from '@polkadot/util-crypto' ;
3+ import { ApiPromise , WsProvider } from '@polkadot/api' ;
34
4- const chainSpec = fs . readFileSync ( './node/chain-specs/bulletin-polkadot.json' , 'utf8' ) ;
5- const client = smoldot . start ( ) ;
65
7- await client
8- . addChain ( { chainSpec } )
9- . then ( ( chain ) => {
10- chain . sendJsonRpc ( `{"jsonrpc":"2.0","id":12,"method":"chain_getFinalizedHead","params":[]}` ) ;
11- return chain ;
12- } )
13- . then ( async ( chain ) => {
14- const response = await chain . nextJsonRpcResponse ( ) ;
15- console . log ( "✅ JSON-RPC response:" , response ) ;
16- } )
17- . then ( ( ) => client . terminate ( ) )
6+ async function main ( ) {
7+ await cryptoWaitReady ( ) ;
8+
9+ const ws = new WsProvider ( 'wss://bulletin.rpc.amforc.com' ) ;
10+ const api = await ApiPromise . create ( { provider : ws } ) ;
11+ await api . isReady ;
12+
13+ // true: raw chain spec
14+ const chainSpec = await api . rpc . syncstate . genSyncSpec ( true ) ;
15+
16+ const client = smoldot . start ( ) ;
17+
18+ await client
19+ . addChain ( { chainSpec : chainSpec . toString ( ) } )
20+ . then ( ( chain ) => {
21+ chain . sendJsonRpc ( `{"jsonrpc":"2.0","id":12,"method":"chain_getFinalizedHead","params":[]}` ) ;
22+ return chain ;
23+ } )
24+ . then ( async ( chain ) => {
25+ const response = await chain . nextJsonRpcResponse ( ) ;
26+ console . log ( "✅ JSON-RPC response:" , response ) ;
27+ return chain ;
28+ } )
29+ . then ( ( ) => client . terminate ( ) ) ;
30+ }
31+
32+ await main ( ) ;
0 commit comments