-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
94 lines (75 loc) · 2.95 KB
/
index.js
File metadata and controls
94 lines (75 loc) · 2.95 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// import { Actor, HttpAgent } from "@dfinity/agent";
// // Imports and re-exports candid interface
// import { idlFactory } from "./dfinance_backend.did.js";
// export { idlFactory } from "./dfinance_backend.did.js";
// /* CANISTER_ID is replaced by webpack based on node environment
// * Note: canister environment variable will be standardized as
// * process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
// * beginning in dfx 0.15.0
// */
// export const canisterId =
// "avqkn-guaaa-aaaaa-qaaea-cai";
// export const createActor = (canisterId, options = {}) => {
// const agent = options.agent || new HttpAgent({ ...options.agentOptions });
// if (options.agent && options.agentOptions) {
// console.warn(
// "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
// );
// }
// // Fetch root key for certificate validation during development
// if ("local" !== "ic") {
// agent.fetchRootKey().catch((err) => {
// console.warn(
// "Unable to fetch root key. Check to ensure that your local replica is running"
// );
// console.error(err);
// });
// }
// // Creates an actor with using the candid interface and the HttpAgent
// return Actor.createActor(idlFactory, {
// agent,
// canisterId,
// ...options.actorOptions,
// });
// };
// export const dfinance_backend = canisterId ? createActor(canisterId) : undefined;
import { Actor, HttpAgent } from "@dfinity/agent";
// Imports and re-exports candid interface
import { idlFactory } from "./dfinance_backend.did.js";
export { idlFactory } from "./dfinance_backend.did.js";
/* CANISTER_ID is replaced by webpack based on node environment
* Note: canister environment variable will be standardized as
* process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
* beginning in dfx 0.15.0
*/
const network = "local";
export const canisterId =
"avqkn-guaaa-aaaaa-qaaea-cai";
export const createActor = (canisterId, options = {}) => {
// const agent = options.agent || new HttpAgent({ ...options.agentOptions });
const agent = new HttpAgent({
host: network === "local" ? "http://127.0.0.1:4943" : undefined,
...options.agentOptions,
});
if (options.agent && options.agentOptions) {
console.warn(
"Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
);
}
// Fetch root key for certificate validation during development
if (network === "local") {
agent.fetchRootKey().catch((err) => {
console.warn(
"Unable to fetch root key. Check to ensure that your local replica is running"
);
console.error(err);
});
}
// Creates an actor with using the candid interface and the HttpAgent
return Actor.createActor(idlFactory, {
agent,
canisterId,
...options.actorOptions,
});
};
export const dfinance_backend = canisterId ? createActor(canisterId) : undefined;