blockchain-utils-service 1.0.0 → 1.0.2

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.0",
3
+ "version": "1.0.2",
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.6.7",
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
  /**
@@ -8,51 +8,50 @@
8
8
  * @param {Object} config - Subscription configuration.
9
9
  * @param {string} config.name - A name for the webhook subscription.
10
10
  * @param {number|string} config.chainId - The chain ID of the blockchain network (e.g., 137 for Polygon).
11
- * @param {string} config.contractAddress - The address of the deployed smart contract.
11
+ * @param {string} config.address - The address of the deployed smart contract.
12
12
  * @param {string} config.thirdwebInsightUrl - The base URL for the Thirdweb Insight API.
13
- * @param {string[]} config.eventsSignature - An array of event signatures to listen for (e.g., ["Transfer(address,address,uint256)"]).
13
+ * @param {string[]} config.eventSignatures - An array of event signatures to listen for (e.g., ["Transfer(address,address,uint256)"]).
14
14
  * @param {string} config.secretKey - Secret key for authenticating with the Thirdweb Insight.
15
15
  * @param {string} config.abi - The contract's ABI (Application Binary Interface), required to decode events.
16
- * @param {string} config.webhookUrl - The URL where event notifications will be sent.
16
+ * @param {string} config.streamingWebhookUrl - The URL where event notifications will be sent.
17
17
  * @param {string} config.environment - The Development Environment.
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
- contractAddress,
24
+ address,
24
25
  inhouseStreamUrl,
25
- eventsSignature,
26
- webhookUrl,
26
+ eventSignatures,
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`;
32
35
  const body = {
33
36
  chainId,
34
- contractAddress,
35
- eventsSignature,
36
- webhookUrl,
37
+ address,
38
+ eventSignatures,
39
+ streamingWebhookUrl,
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 response = await fetch(uri, {
44
- method: "POST",
45
- headers: headers,
46
- body: JSON.stringify(body),
48
+ const res = await axios.post(uri, body, {
49
+ headers: headers
47
50
  });
48
- const result = await response.json();
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
- console.log(error)
55
- return { isSuccess: false, data: `Webhook creation failed: ${JSON.stringify(error.message)}` };
53
+ const errData = error.response?.data || error.message;
54
+ return { isSuccess: false, data: `Webhook creation failed: ${JSON.stringify(errData)}` };
56
55
  }
57
56
  }
58
57
 
@@ -60,29 +59,35 @@ export async function contractSubscribeWebhook({
60
59
  /**
61
60
  * Updates a Thirdweb Insight Webhook status.
62
61
  *
63
- * @param {string} webhookId – The ID of the webhook to be updated.
62
+ * @param {string} subscriptionId – The ID of the webhook to be updated.
64
63
  * @param {boolean} disabledFlag – The new status for the webhook, either "true" (to disable) or "false" (to enable).
65
64
  * @param {string} inhouseStreamUrl - The base URL for the Thirdweb Insight API.
66
65
  * @returns {Promise<{isSuccess: boolean, data: any}>}
67
66
  */
68
- export async function updateWebhookStatus({ streamId, status, inhouseStreamUrl }) {
69
- if (!streamId || !inhouseStreamUrl || !status) {
67
+ export async function updateWebhookStatus({
68
+ subscriptionId,
69
+ status,
70
+ inhouseStreamUrl,
71
+ streamingUserAuth,
72
+ streamingPassAuth
73
+ }) {
74
+ if (!subscriptionId || !inhouseStreamUrl || !status) {
70
75
  return { isSuccess: false, data: "Missing required parameters" };
71
76
  }
72
77
  try {
73
- const uri = `${inhouseStreamUrl}/streams/evm/${streamId}/status`;
78
+ const uri = `${inhouseStreamUrl}/streams/evm/${subscriptionId}/status`;
74
79
  const body = { status };
80
+ const token = btoa(`${streamingUserAuth}:${streamingPassAuth}`);
75
81
  const headers = {
76
- "Content-Type": "application/json"
82
+ "Content-Type": "application/json",
83
+ "Authorization": `Basic ${token}`,
77
84
  };
78
- const response = await fetch(uri, { method: "POST", headers, body: JSON.stringify(body) });
79
- if (!response.ok) {
80
- const errorData = await response.json();
81
- throw new Error(`UpdateWebhookStatus Failed: ${errorData}`);
82
- }
83
- const result = await response.json();
84
- return { isSuccess: true, data: result };
85
+ const res = await axios.post(uri, body, {
86
+ headers: headers
87
+ });
88
+ return { isSuccess: true, data: res.data };
85
89
  } catch (error) {
86
- return { isSuccess: false, data: JSON.stringify(error) };
90
+ const errData = error.response?.data || error.message;
91
+ return { isSuccess: false, data: JSON.stringify(errData) };
87
92
  }
88
93
  }
@@ -7,7 +7,7 @@ import { defineChain } from 'thirdweb/chains';
7
7
  * Checks whether the current block number on the blockchain has reached or surpassed a specified target block number.
8
8
  *
9
9
  * @param {Object} config - Configuration for the block check.
10
- * @param {string} config.chainId - The ChainId
10
+ * @param {string} config.chainId - The ChainId of the blockchain to check.
11
11
  * @param {string} config.clientId - The Thirdweb API clientId used for authentication (if required).
12
12
  * @param {number} config.targetBlockNumber - The target block number to compare against.
13
13
  * @returns {Promise<boolean>} - Returns `true` if the current block number is greater than or equal to the target, otherwise `false`.
package/src/index.js CHANGED
@@ -4,7 +4,6 @@ export { fetchContractEvents } from "./getEvents.js";
4
4
  export { hasBlockNumberReached } from "./getBlockNumberReached.js";
5
5
  export { contractSubscribeWebhook, updateWebhookStatus } from "./contractSubscribeWebhook.js";
6
6
  export { getTransactionHash } from "./getTransactionHash.js";
7
- export { fetchTokenLatestPrice } from "./getTokenLatestPrice.js";
8
7
  export { getTokenPrice } from "./getTokenPrice.js";
9
8
  export { findDeploymentTxHash } from "./getCreatorTxHash.js";
10
9
  export { readTransaction } from "./readTransaction.js";
package/src/transfer.js CHANGED
@@ -14,16 +14,11 @@
14
14
  // #Review Pending
15
15
  export const transferFunds = async ({ recipient, chainId, amount, engineUrl, authorizationToken, backendWalletAddress }) => {
16
16
  try {
17
- if ((amount) > 1) {
18
- throw new Error(`More than 1 Eth not supported!`);
19
- }
20
-
21
17
  const url = `${engineUrl}/backend-wallet/${chainId}/transfer`
22
18
  const headers = {
23
19
  "Content-Type": "application/json",
24
20
  Authorization: `Bearer ${authorizationToken}`,
25
21
  "x-backend-wallet-address": backendWalletAddress,
26
- "x-idempotency-key": `idemp-${Date.now()}`,
27
22
  };
28
23
  const body = JSON.stringify({
29
24
  to: recipient,
@@ -40,7 +35,5 @@ export const transferFunds = async ({ recipient, chainId, amount, engineUrl, aut
40
35
  return result
41
36
  } catch (error) {
42
37
  throw new Error(`Failed to transfer: ${error}`);
43
-
44
38
  }
45
-
46
39
  }
@@ -1,33 +0,0 @@
1
- /**
2
- * Finds the deployment transaction hash for a given smart contract address on a specific blockchain.
3
- *
4
- * @param {string} contractAddress - The address of the deployed smart contract.
5
- * @param {number|string} chainId - The chain ID of the blockchain network (e.g., 1 for Ethereum Mainnet, 137 for Polygon).
6
- * @param {string} apiKey - The API key Moralis
7
- * @returns {Promise<object|null>} - Returns { tokenName, tokenSymbol, usdPrice }.
8
- */
9
- export async function fetchTokenLatestPrice({ contractAddress, chainId, apiKey }) {
10
- try {
11
- if (!contractAddress || !chainId || !apiKey) {
12
- throw new Error("Missing required parameters for fetchTokenLatestPrice");
13
- }
14
- const hexChainId = '0x' + chainId.toString(16);
15
- const headers = {
16
- "Content-Type": "application/json",
17
- "x-api-key": apiKey,
18
- };
19
- const apiUrl = `https://deep-index.moralis.io/api/v2.2/erc20/${contractAddress}/price?chain=${hexChainId}&include=percent_change`;
20
- const response = await fetch(apiUrl, {
21
- method: 'GET',
22
- headers: headers
23
- });
24
- if (!response.ok) {
25
- const errorData = await response.json();
26
- throw new Error(`Fetching price failed: ${JSON.stringify(errorData)}`);
27
- }
28
- const { usdPrice, tokenName, tokenSymbol } = await response.json();
29
- return { tokenName, tokenSymbol, usdPrice };
30
- } catch (err) {
31
- throw new Error(`Failed to fetch latest price for ${contractAddress} at ${chainId} : ${err.message}`);
32
- }
33
- }