How to connect web3 to ethereum network using flutter?

丶灬走出姿态 提交于 2019-12-10 23:36:28

问题


i am getting error while connecting with ethereum node

  • this line ==> print(client.getBlockNumber()); returns error

E/flutter (22015): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: Failed host lookup: 'localhost:8545' (OS Error: No address associated with hostname, errno = 7)

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:web3dart/web3dart.dart';
import 'dart:async';
const String url =
    'https://mainnet.infura.io'; // i am also running geth on local http://localhost:8545

class HomeScreen extends StatefulWidget {
    @override
    State<StatefulWidget> createState() {
        return _HomeScreenState();
    }
}

class _HomeScreenState extends State<HomeScreen> {
    @override
    void initState() {
        main();
        super.initState();
    }
    main() {
        final httpClient =new Client();
        final client =new  Web3Client(url, httpClient);
        print(client.getBlockNumber());
    }
}

回答1:


Port 8545 on Localhost is generally used when you are doing some development on Local Ethereum Blockchain Network. Most probable cause in this case is that you are not running a Client or Wallet service like Ganache from where the injection is going to take place. Ganache creates a local wallet and gives you 10 development Eth Address to work with. You can use that with your App. Your RPC port here is 8545.



来源:https://stackoverflow.com/questions/55393249/how-to-connect-web3-to-ethereum-network-using-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!