以太坊节点拒绝连接

时间:2019-04-16 06:52:05

标签: web3js

我正在使用ganache-cli帮助连接到android应用程序中的以太坊节点,但是每当我尝试连接到该节点时,该应用程序就会中断。

我声明了IP并将其张贴在web3jContraints文件中,并将其称为我的Login类,但是由于未连接节点,因此只要需要从库中调用函数,应用程序就会中断。

  //connect the moible device to the ethereum client node
 public void Start_Connect() {
    clientUrl = argsToUrl();
    web3j = Web3jFactory.build(new HttpService(clientUrl));
}

//connection port and ip
public String argsToUrl() {
    String ip = web3jconstants.CLIENT_IP;
    String port = web3jconstants.CLIENT_PORT;

    return String.format("http://%s:%s", ip, port);
}

//get the coinbase of the ethereum wallet
public static EthCoinbase getCoinbase(Web3j web3j) throws InterruptedException, ExecutionException {
    return web3j
            .ethCoinbase()
            .sendAsync()
            .get();
}
 //code for the connection web3constraint file
 public class web3jconstants {

    //connection port
    public static final String CLIENT_IP = "127.0.0.1";//"10.97.174.70";
    public static final String CLIENT_PORT = "8545";

0 个答案:

没有答案