rpcApi.dart 495 B

1234567891011121314151617181920
  1. import 'dart:convert';
  2. import 'package:http/http.dart';
  3. const post_headers = {"Content-type": "application/json", "Accept": "*/*"};
  4. class EvmRpcApi {
  5. static Future<Map> getRpcCall(String endpoint, Map payload) async {
  6. final url = '$endpoint';
  7. try {
  8. final res = await post(Uri.parse(url),
  9. body: jsonEncode(payload), headers: post_headers);
  10. return jsonDecode(utf8.decode(res.bodyBytes)) as Map;
  11. } catch (err) {
  12. print(err);
  13. return {};
  14. }
  15. }
  16. }