How to connect web3 to ethereum network using flutter?
Asked Answered
I

1

2

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());
    }
}
Induna answered 28/3, 2019 at 8:40 Comment(6)
Same goes here: #54638125Corsica
@Corsica any Solution? How can i use web3 connection in flutter?Induna
Have you read that answer?Corsica
yes i have seen your answer but that is not a solution in my caseInduna
You'll need to explain how that is not a solution. What's different about your case?Suave
@RandalSchwartz because i am using infura, that's why i do't need to disable any firewall or replacing localhost:8080 with 10.0.2.2Induna
A
-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.

Arbe answered 7/6, 2019 at 14:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.