blockchain-utils-service 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blockchain-utils-service",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A lightweight service for deploying contracts, writing transactions, reading events, and checking block numbers.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@thirdweb-dev/sdk": "^4.0.99",
|
|
23
|
-
"axios": "^1.
|
|
23
|
+
"axios": "^1.13.2",
|
|
24
24
|
"dotenv": "^16.3.0",
|
|
25
25
|
"ethers": "^5.8.0",
|
|
26
26
|
"thirdweb": "^5.104.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/contractSubscribeWebhook.js
|
|
2
|
-
|
|
2
|
+
import axios from "axios";
|
|
3
3
|
// #pending
|
|
4
4
|
// Add check webhook URL function!
|
|
5
5
|
/**
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* @param {string} config.subscriptionType - The type of webhook e.g. "activityType" or "eventType"
|
|
19
19
|
* @returns {Promise<Object>} - Result of the webhook subscription, typically includes subscription ID or status.
|
|
20
20
|
*/
|
|
21
|
+
//#Pending , pass stremaing auth dynamic
|
|
21
22
|
export async function contractSubscribeWebhook({
|
|
22
23
|
chainId,
|
|
23
24
|
address,
|
|
@@ -25,7 +26,9 @@ export async function contractSubscribeWebhook({
|
|
|
25
26
|
eventSignatures,
|
|
26
27
|
streamingWebhookUrl,
|
|
27
28
|
environment,
|
|
28
|
-
subscriptionType
|
|
29
|
+
subscriptionType,
|
|
30
|
+
streamingUserAuth,
|
|
31
|
+
streamingPassAuth
|
|
29
32
|
}) {
|
|
30
33
|
try {
|
|
31
34
|
const uri = `${inhouseStreamUrl}/streams/evm`;
|
|
@@ -37,21 +40,18 @@ export async function contractSubscribeWebhook({
|
|
|
37
40
|
environment,
|
|
38
41
|
subscriptionType
|
|
39
42
|
};
|
|
43
|
+
const token = btoa(`${streamingUserAuth}:${streamingPassAuth}`);
|
|
40
44
|
const headers = {
|
|
41
45
|
"Content-Type": "application/json",
|
|
46
|
+
"Authorization": `Basic ${token}`,
|
|
42
47
|
};
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
headers: headers,
|
|
46
|
-
body: JSON.stringify(body),
|
|
48
|
+
const res = await axios.post(uri, body, {
|
|
49
|
+
headers: headers
|
|
47
50
|
});
|
|
48
|
-
|
|
49
|
-
if (!response.ok) {
|
|
50
|
-
throw new Error(`Failed - Webhook Creation for contract: ${JSON.stringify(result)}`);
|
|
51
|
-
}
|
|
52
|
-
return { isSuccess: true, data: { webhookResponse: result } };
|
|
51
|
+
return { isSuccess: true, data: { webhookResponse: res.data } };
|
|
53
52
|
} catch (error) {
|
|
54
|
-
|
|
53
|
+
const errData = error.response?.data || error.message;
|
|
54
|
+
return { isSuccess: false, data: `Webhook creation failed: ${JSON.stringify(errData)}` };
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -64,24 +64,30 @@ export async function contractSubscribeWebhook({
|
|
|
64
64
|
* @param {string} inhouseStreamUrl - The base URL for the Thirdweb Insight API.
|
|
65
65
|
* @returns {Promise<{isSuccess: boolean, data: any}>}
|
|
66
66
|
*/
|
|
67
|
-
export async function updateWebhookStatus({
|
|
67
|
+
export async function updateWebhookStatus({
|
|
68
|
+
subscriptionId,
|
|
69
|
+
status,
|
|
70
|
+
inhouseStreamUrl,
|
|
71
|
+
streamingUserAuth,
|
|
72
|
+
streamingPassAuth
|
|
73
|
+
}) {
|
|
68
74
|
if (!subscriptionId || !inhouseStreamUrl || !status) {
|
|
69
75
|
return { isSuccess: false, data: "Missing required parameters" };
|
|
70
76
|
}
|
|
71
77
|
try {
|
|
72
78
|
const uri = `${inhouseStreamUrl}/streams/evm/${subscriptionId}/status`;
|
|
73
79
|
const body = { status };
|
|
80
|
+
const token = btoa(`${streamingUserAuth}:${streamingPassAuth}`);
|
|
74
81
|
const headers = {
|
|
75
|
-
"Content-Type": "application/json"
|
|
82
|
+
"Content-Type": "application/json",
|
|
83
|
+
"Authorization": `Basic ${token}`,
|
|
76
84
|
};
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
const result = await response.json();
|
|
83
|
-
return { isSuccess: true, data: result };
|
|
85
|
+
const res = await axios.post(uri, body, {
|
|
86
|
+
headers: headers
|
|
87
|
+
});
|
|
88
|
+
return { isSuccess: true, data: res.data };
|
|
84
89
|
} catch (error) {
|
|
85
|
-
|
|
90
|
+
const errData = error.response?.data || error.message;
|
|
91
|
+
return { isSuccess: false, data: JSON.stringify(errData) };
|
|
86
92
|
}
|
|
87
93
|
}
|
package/src/writeTransaction.js
CHANGED
|
@@ -41,6 +41,8 @@ export async function writeTransaction({
|
|
|
41
41
|
"x-backend-wallet-address": backendWalletAddress,
|
|
42
42
|
"x-idempotency-key": `idemp-${Date.now()}`,
|
|
43
43
|
};
|
|
44
|
+
console.log("AUTH TOKEN RECEIVED:", authorizationToken);
|
|
45
|
+
console.log("HEADERS USED:", headers);
|
|
44
46
|
const body = JSON.stringify({ functionName, args });
|
|
45
47
|
const response = await fetch(writeUrl, { method: "POST", headers, body });
|
|
46
48
|
if (!response.ok) {
|