okhttp eth_call

2023-10-24  本文已影响0人  侧耳倾听y

String json = "{\n" +
                "    \"jsonrpc\": \"2.0\",\n" +
                "    \"method\": \"eth_call\",\n" +
                "    \"params\": [\n" +
                "        \n" +
                "            {\n" +
                "                \"from\": \"0x0000000000000000000000000000000000000000\",\n" +
                "                \"to\": \"" + contract + "\",\n" +
                "                \"data\": \"" + inputData + "\"\n" +
                "            },\n" +
                "        \n" +
                "        \"latest\"\n" +
                "    ],\n" +
                "    \"id\": 1\n" +
                "}";
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        Request request = new Request.Builder()
                .url("https://eth-mainnet.public.blastapi.io")
                .post(requestBody)
                .build();

        Call call = okHttpClient.newCall(request);
        Response execute = call.execute();
        String s = execute.body().string();
        String message = JSON.parseObject(s).getString("result");
上一篇 下一篇

猜你喜欢

热点阅读