UNPKG

722 BJavaScriptView Raw
1"use strict";
2
3// Copyright 2017-2018 Jaco Greeff
4// This software may be modified and distributed under the terms
5// of the ISC license. See the LICENSE file for details.
6const assert = require('@polkadot/util/assert');
7
8module.exports = async function send({
9 coder,
10 endpoint
11}, method, params) {
12 const body = coder.encodeJson(method, params);
13 const response = await fetch(endpoint, {
14 body,
15 headers: {
16 'Accept': 'application/json',
17 'Content-Length': `${body.length}`,
18 'Content-Type': 'application/json'
19 },
20 method: 'POST'
21 });
22 assert(response.ok, `[${response.status}]: ${response.statusText}`);
23 const result = await response.json();
24 return coder.decodeResponse(result);
25};
\No newline at end of file