@wopr-network/platform-core 1.63.0 → 1.63.1

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.
@@ -47,5 +47,5 @@ export declare class EvmWatcher {
47
47
  poll(): Promise<void>;
48
48
  }
49
49
  /** Create an RPC caller for a given URL (plain JSON-RPC over fetch). */
50
- export declare function createRpcCaller(rpcUrl: string): RpcCall;
50
+ export declare function createRpcCaller(rpcUrl: string, extraHeaders?: Record<string, string>): RpcCall;
51
51
  export {};
@@ -133,12 +133,23 @@ export class EvmWatcher {
133
133
  }
134
134
  }
135
135
  /** Create an RPC caller for a given URL (plain JSON-RPC over fetch). */
136
- export function createRpcCaller(rpcUrl) {
136
+ export function createRpcCaller(rpcUrl, extraHeaders) {
137
137
  let id = 0;
138
+ // Extract apikey query param and pass as TRON-PRO-API-KEY header (TronGrid JSON-RPC ignores query params)
139
+ const headers = { "Content-Type": "application/json", ...extraHeaders };
140
+ try {
141
+ const url = new URL(rpcUrl);
142
+ const apiKey = url.searchParams.get("apikey");
143
+ if (apiKey)
144
+ headers["TRON-PRO-API-KEY"] = apiKey;
145
+ }
146
+ catch {
147
+ // Not a valid URL — proceed without extra headers
148
+ }
138
149
  return async (method, params) => {
139
150
  const res = await fetch(rpcUrl, {
140
151
  method: "POST",
141
- headers: { "Content-Type": "application/json" },
152
+ headers,
142
153
  body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
143
154
  });
144
155
  if (!res.ok)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/platform-core",
3
- "version": "1.63.0",
3
+ "version": "1.63.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -180,12 +180,21 @@ export class EvmWatcher {
180
180
  }
181
181
 
182
182
  /** Create an RPC caller for a given URL (plain JSON-RPC over fetch). */
183
- export function createRpcCaller(rpcUrl: string): RpcCall {
183
+ export function createRpcCaller(rpcUrl: string, extraHeaders?: Record<string, string>): RpcCall {
184
184
  let id = 0;
185
+ // Extract apikey query param and pass as TRON-PRO-API-KEY header (TronGrid JSON-RPC ignores query params)
186
+ const headers: Record<string, string> = { "Content-Type": "application/json", ...extraHeaders };
187
+ try {
188
+ const url = new URL(rpcUrl);
189
+ const apiKey = url.searchParams.get("apikey");
190
+ if (apiKey) headers["TRON-PRO-API-KEY"] = apiKey;
191
+ } catch {
192
+ // Not a valid URL — proceed without extra headers
193
+ }
185
194
  return async (method: string, params: unknown[]): Promise<unknown> => {
186
195
  const res = await fetch(rpcUrl, {
187
196
  method: "POST",
188
- headers: { "Content-Type": "application/json" },
197
+ headers,
189
198
  body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
190
199
  });
191
200
  if (!res.ok) throw new Error(`RPC ${method} failed: ${res.status}`);