UNPKG

ethjs-provider-http

Version:

A simple Http provider that follows the web3 spec.

1 lines 2.2 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("HttpProvider",[],e):"object"==typeof exports?exports.HttpProvider=e():t.HttpProvider=e()}(this,function(){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var r={};return e.m=t,e.c=r,e.i=function(t){return t},e.d=function(t,e,r){Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e,r){"use strict";function o(t,e){var r=Error("[ethjs-provider-http] Invalid JSON RPC response from provider\n host: "+e+"\n response: "+(t.responseText+"")+" "+JSON.stringify(t.responseText,null,2)+"\n responseURL: "+t.responseURL+"\n status: "+t.status+"\n statusText: "+t.statusText+"\n ");return r.value=t,r}function n(t,e){if(!(this instanceof n))throw Error('[ethjs-provider-http] the HttpProvider instance requires the "new" flag in order to function normally (e.g. `const eth = new Eth(new HttpProvider());`).');if("string"!=typeof t)throw Error('[ethjs-provider-http] the HttpProvider instance requires that the host be specified (e.g. `new HttpProvider("http://localhost:8545")` or via service like infura `new HttpProvider("http://ropsten.infura.io")`)');var r=this;r.host=t,r.timeout=e||0}var i=r(1);n.prototype.sendAsync=function(t,e){var r=this,n=new i;n.timeout=r.timeout,n.open("POST",r.host,!0),n.setRequestHeader("Content-Type","application/json"),n.onreadystatechange=function(){if(4===n.readyState&&1!==n.timeout){var t=n.responseText,i=null;try{t=JSON.parse(t)}catch(s){i=o(n,r.host)}e(i,t)}},n.ontimeout=function(){e("[ethjs-provider-http] CONNECTION TIMEOUT: http request timeout after "+r.timeout+" ms. (i.e. your connect has timed out for whatever reason, check your provider).",null)};try{n.send(JSON.stringify(t))}catch(s){e("[ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node '"+r.host+"': "+JSON.stringify(s,null,2),null)}},t.exports=n},function(t,e){t.exports=XMLHttpRequest},function(t,e,r){t.exports=r(0)}])});