ws.ts 587 B

1234567891011121314151617
  1. import { ApiPromise, WsProvider } from '@polkadot/api'
  2. import { types } from '@joystream/types'
  3. import { wsLocation } from '../config.json'
  4. export const connectUpstream = async (): Promise<ApiPromise> => {
  5. console.debug(`[Joystream] Connecting to ${wsLocation}`)
  6. try {
  7. const provider = new WsProvider(wsLocation)
  8. const api = await ApiPromise.create({ provider, types })
  9. await api.isReady
  10. console.debug(`[Joystream] Connected to ${wsLocation}`)
  11. return api
  12. } catch (e) {
  13. console.error(`[Joystream] upstream connection failed`, e)
  14. throw new Error()
  15. }
  16. }