generated from TENK-DAO/frontend-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
50 lines (43 loc) · 1.35 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
import * as naj from "near-api-js"
import settings from "../../config/settings.json"
const { contractName } = settings
// TODO: remove pending https://github.com/near/near-api-js/issues/757
import { Buffer } from "buffer"
if (typeof window !== "undefined") window.Buffer = Buffer
if (typeof global !== "undefined") global.Buffer = Buffer
const nearConfig = /near$/.test(contractName)
? {
networkId: "mainnet",
nodeUrl: "https://rpc.mainnet.near.org",
walletUrl: "https://wallet.near.org",
helperUrl: "https://helper.mainnet.near.org",
}
: /testnet$/.test(contractName)
? {
networkId: "testnet",
nodeUrl: "https://rpc.testnet.near.org",
walletUrl: "https://wallet.testnet.near.org",
helperUrl: "https://helper.testnet.near.org",
}
: undefined
if (!nearConfig) {
throw new Error(
`Don't know what network settings to use for contract "${contractName}"; expected name to end in 'testnet' or 'near'`
)
}
/**
* NEAR Config object
*/
export const near = new naj.Near({
...nearConfig,
keyStore: typeof window === "undefined"
? new naj.keyStores.InMemoryKeyStore()
: new naj.keyStores.BrowserLocalStorageKeyStore()
})
/**
* Interface to NEAR Wallet
*/
export const wallet = new naj.WalletConnection(near)
export function signIn() {
wallet.requestSignIn({ contractId: settings.contractName })
}