Browse Source

api: connectApi()

Joystream Stats 3 years ago
parent
commit
1e473e570a
1 changed files with 7 additions and 2 deletions
  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);