@polkadot/types/types#OverrideModuleType TypeScript Examples

The following examples show how to use @polkadot/types/types#OverrideModuleType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From moonbeam with GNU General Public License v3.0 5 votes vote down vote up
moduleDefinitions: Record<string, OverrideModuleType> = {
  assetManager: {
    Balance: "TAssetBalance",
  },
  xTokens: {
    Balance: "TAssetBalance",
  },
}
Example #2
Source File: index.ts    From squid with GNU General Public License v3.0 5 votes vote down vote up
export async function getApiPromise(): Promise<ApiPromise> {
  if (apiPromise) {
    return apiPromise
  }

  debug(`Creating new Api Promise`)

  const conf = getConfig()
  const provider = new WsProvider(conf.WS_PROVIDER_ENDPOINT_URI)

  const names = Object.keys(conf.TYPES_JSON)

  names.length && debug(`Injected types: ${names.join(', ')}`)

  apiPromise = await pRetry(
    async () =>
      new ApiPromise({
        provider,
        types: conf.TYPES_JSON as RegistryTypes,
        typesAlias: conf.TYPES_ALIAS as Record<string, OverrideModuleType>,
        typesBundle: conf.BUNDLE_TYPES as OverrideBundleType,
        typesSpec: conf.SPEC_TYPES as Record<string, RegistryTypes>,
        typesChain: conf.CHAIN_TYPES as Record<string, RegistryTypes>,
      }).isReadyOrError,
    {
      retries: 99, // large enough
      onFailedAttempt: (error) =>
        debug(`API failed to connect: ${JSON.stringify(error)}`),
    }
  )

  apiPromise.on('error', async (e) => {
    debug(`Api error: ${JSON.stringify(e)}, reconnecting....`)
    apiPromise = await getApiPromise()
  })

  apiPromise.on('connected', () => {
    debug(`Api connected`)
    eventEmitter.emit(IndexerEvents.API_CONNECTED)
  })

  return apiPromise
}