18 lines
681 B
TypeScript
18 lines
681 B
TypeScript
|
|
/**
|
||
|
|
* Shared JSON-RPC utility for holdout helpers.
|
||
|
|
*
|
||
|
|
* Exported from one place so wallet.ts, assertions.ts, and future helpers
|
||
|
|
* share a single implementation rather than embedding the same fetch +
|
||
|
|
* error-check block in each file.
|
||
|
|
*/
|
||
|
|
export async function rpcCall(rpcUrl: string, method: string, params: unknown[]): Promise<unknown> {
|
||
|
|
const resp = await fetch(rpcUrl, {
|
||
|
|
method: 'POST',
|
||
|
|
headers: { 'content-type': 'application/json' },
|
||
|
|
body: JSON.stringify({ jsonrpc: '2.0', id: Date.now(), method, params }),
|
||
|
|
});
|
||
|
|
const payload = await resp.json();
|
||
|
|
if (payload.error) throw new Error(`RPC ${method}: ${payload.error.message}`);
|
||
|
|
return payload.result;
|
||
|
|
}
|