-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnear-api.ts
39 lines (34 loc) · 1.03 KB
/
near-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { ConfigService } from '@nestjs/config';
import { Account, Near, providers } from 'near-api-js';
import { Provider } from 'near-api-js/lib/providers';
import { NEAR_PROVIDER, NEAR_API_PROVIDER } from '@sputnik-v2/common';
export type NearApiContract = {
contractId?: string;
viewMethods: string[];
changeMethods: string[];
};
export type NearApiProvider = {
provider: Provider;
near: Near;
account: Account;
sputnikDaoFactoryContractName: string;
};
export const nearApiProvider = {
provide: NEAR_API_PROVIDER,
inject: [ConfigService, NEAR_PROVIDER],
useFactory: async (configService: ConfigService, near: Near) => {
const config = configService.get('near');
const { contractName, providerUrl, providerHeaders } = config;
const account = await near.account(contractName);
const provider = new providers.JsonRpcProvider({
url: providerUrl,
headers: providerHeaders,
});
return {
near,
account,
provider,
sputnikDaoFactoryContractName: contractName,
};
},
};