UNPKG

@iam4x/bsc-scan

Version:

An efficient BNB and token balance scanner

6 lines 933 B
import fetch from"isomorphic-unfetch";/** * A raw HTTP provider, which can be used with an Ethereum node endpoint (JSON-RPC), or an `HttpProviderOptions` object. */const provider={isProvider:a=>"string"==typeof a||"object"==typeof a&&void 0!==a.url,call:async(a,b,c)=>{const d="string"==typeof a?a:a.url,e="object"==typeof a?a.params:{},f=getPayload(b,c),g=await fetch(d,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(f),cache:"no-cache",...e});if(!g.ok)throw new Error(`Contract call failed with HTTP error ${g.status}: ${g.statusText}`);const{error:h,result:i}=await g.json();if(h)throw new Error(`Contract call failed: ${h.message}`);return i}};export default provider;/** * Get the JSON-RPC payload for the `eth_call` function. */export const getPayload=(a,b)=>({jsonrpc:"2.0",method:"eth_call",params:[{to:a,data:b},"latest"],id:1}); //# sourceMappingURL=http.js.map