1
0

ws.ts 701 B

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