12345678910111213141516171819202122 |
- // TODO allow alternative backends
- import { ApiPromise, WsProvider } from '@polkadot/api'
- import { types } from '@joystream/types'
- const wsLocation = 'ws://localhost:9944'
- export const connectUpstream = async (): Promise<ApiPromise> => {
- try {
- //console.debug(`[Joystream] Connecting to ${wsLocation}`)
- const provider = new WsProvider(wsLocation)
- const api = await ApiPromise.create({ provider, types })
- await api.isReady
- console.debug(`[Joystream] Connected to ${wsLocation}`)
- return api
- } catch (e) {
- console.error(`[Joystream] upstream connection failed`, e)
- throw new Error()
- }
- }
- module.exports = { connectUpstream }
|