当前位置: 首页 > 工具软件 > jsonrpc4j > 使用案例 >

java https jasonrpc_以太坊 ethereum JSON-RPC java 调用示例

冀俊良
2023-12-01

启动 geth

在启动时需要开启 rpc 的支持:

geth --identity "ethtest" --rpc --rpcaddr 10.200.123.19 --port 10071 --rpcport 10070 --rpcapi "personal,db,eth,net,web3" --datadir /data/ethdata --nodiscover --networkid 666

_ rpcaddr_ 指定自己IP后就可以被远程访问,比较方便。

java 代码

maven引入包:

com.github.briandilley.jsonrpc4j

jsonrpc4j

1.5.3

调用代码:

import java.net.URL;

import java.util.HashMap;

import java.util.Map;

import com.googlecode.jsonrpc4j.JsonRpcHttpClient;

public class Test {

public static void main(String[] args) throws Throwable {

Map headers = new HashMap(1);

headers.put("Content-Type", "application/json");

JsonRpcHttpClient client = new JsonRpcHttpClient(new URL("http://10.200.123.19:10070"), headers);

Object result = client.invoke("eth_accounts", args, Object.class);

System.out.println(result);

}

}

 类似资料: