Explorar o código

api: connectApi()

Joystream Stats %!s(int64=3) %!d(string=hai) anos
pai
achega
1e473e570a
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      api.ts

+ 7 - 2
api.ts

@@ -1,4 +1,4 @@
-import { ApiPromise } from "@polkadot/api";
+import { ApiPromise, WsProvider } from "@polkadot/api";
 import moment from "moment";
 
 // types
@@ -17,7 +17,7 @@ import {
   Moment,
 } from "@polkadot/types/interfaces";
 import { SignedBlock } from "@polkadot/types/interfaces/runtime";
-
+import { types } from "@joystream/types";
 import { PostId, ThreadId } from "@joystream/types/common";
 import { CategoryId, Category, Thread, Post } from "@joystream/types/forum";
 import {
@@ -47,6 +47,11 @@ import { ProposalOf, ProposalDetailsOf } from "@joystream/types/augment/types";
 
 import { WorkerOf } from "@joystream/types/augment-codec/all";
 
+export const connectApi = async (url: string): Promise<ApiPromise> => {
+  const provider = new WsProvider(url);
+  return await ApiPromise.create({ provider, types });
+};
+
 // blocks
 export const getBlock = (api: ApiPromise, hash: Hash): Promise<SignedBlock> =>
   api.rpc.chain.getBlock(hash);