连接到以太坊节点时出现错误



---------------------------------- web3连接代码如下----------- ------------------------------------

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'dart:async';

const String rpcUrls = 'https://node1.bitcoiin.com';
class HomeScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeScreenState();
  }
}
class _HomeScreenState extends State<HomeScreen> {
  @override
  void initState() {
    main();
    super.initState();
  }
  main(){
  var ethClient = new Web3Client(apiUrls, new Client());
  print(ethClient.getBlockNumber());
}

最佳答案

我仍然不知道为什么该解决方案有效,但是我遇到了同样的问题,我尝试用服务器的IP地址替换localhost(例如192.168.1.33)。有效!。

为您的应用尝试以下代码:

main(){
  var httpClient = new Client();
  // You tried the code below and it didn't work
  // var ethClient = new Web3Client('http://localhost:8545', httpClient);

  // Try this code instead. (Replace "192.168.1.33" with the IP of your server)
  var ethClient = new Web3Client('http://192.168.1.33:8545', httpClient);

  print(ethClient.getBlockNumber());
}

关于dart - Flutter-SocketException:连接失败(操作系统错误:网络无法访问,errno = 101),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55400121/

10-11 22:28
查看更多