-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (49 loc) · 1.84 KB
/
index.js
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
//import { HTTPTransport } from '@open-rpc/client-js';
//import casperSDK from 'casper-js-sdk';
const { HTTPTransport } = require('@open-rpc/client-js');
const casperSDK = require('casper-js-sdk');
require('dotenv').config();
const { CasperServiceByJsonRPC } = casperSDK;
const { CasperClient } = casperSDK;
const rpcUrl = process.env.INTEGRATION_RPC_URL;
const authKey = process.env.AUTH_KEY;
class CustomCasperClient extends CasperServiceByJsonRPC {
constructor(url, options) {
super(url);
const transport = new HTTPTransport(url, options);
this.client.requestManager.transports = [transport];
}
}
const customCasperClient = new CustomCasperClient(rpcUrl, {
headers: {
"Authorization": authKey
}
});
const casperClient = new CasperClient("");
casperClient.nodeClient = customCasperClient;
(async function(){
const result = await casperClient.nodeClient.getStatus();
console.log({ result });
try {
const deploy = await casperClient.getDeploy("324e02c36fd0d98c577893a0370efdd2d7a08b6fcc15d4272bafd24005566127");
// console.log({ deploy });
// Format deploy section
const formattedDeploy = deploy.map(item => {
return JSON.parse(
JSON.stringify(
item,
(key, value) =>
value instanceof Uint8Array
? Buffer.from(value).toString("hex")
: Array.isArray(value)
? value.map(v => (typeof v === "object" ? v : JSON.stringify(v)))
: value
)
);
});
console.log("Formatted Deploy:");
console.log(JSON.stringify(formattedDeploy, null, 2));
} catch (error) {
console.error("Error fetching deploy data:", error);
}
})();