@robincore/flutter-dapp-provider
Version:
a javascript ethereum provider injector used as an interface between wallet and dApps. [for flutter]
48 lines • 1.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cross_fetch_1 = __importDefault(require("cross-fetch"));
class RPCall {
constructor(_url) {
this.url = _url;
}
getBlockNumber() {
return this.call({
jsonrpc: '2.0',
method: 'eth_blockNumber',
params: [],
}).then(json => json.result);
}
getBlockByNumber(number) {
return this.call({
jsonrpc: '2.0',
method: 'eth_getBlockByNumber',
params: [number, false],
}).then((json) => json.result);
}
getFilterLogs(filter) {
return this.call({ jsonrpc: '2.0', method: 'eth_getLogs', params: [filter] });
}
call(payload) {
return (0, cross_fetch_1.default)(this.url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
.then((response) => response.json())
.then((json) => {
if (!json.result && json.error) {
console.log('<== rpc error', json.error);
throw new Error(json.error.message || 'rpc error');
}
return json;
});
}
}
exports.default = RPCall;
//# sourceMappingURL=RPCall.js.map