UNPKG

dotbit-sdk-allin

Version:

A complete .bit SDK and utilities in TypeScript

33 lines 968 B
import fetch from 'cross-fetch'; import { DotbitError } from '../errors/DotbitError'; export class JSONRPC { constructor(url) { this.url = url; this.id = 0; } request(method, params = []) { return fetch(this.url, { method: 'POST', body: JSON.stringify({ jsonrpc: '2.0', id: this.id++, method, params, }), headers: { 'Content-Type': 'application/json', }, }) .then(res => res.json()) .then(res => { if (res.error) { throw new DotbitError(res.error.message, res.error.code); } if (res.result.errno) { throw new DotbitError(res.result.errmsg, res.result.errno); } return res.result; }); } } //# sourceMappingURL=JSON-RPC.js.map