如何使用Flutter将Web3连接到以太坊网络? [英] How to connect web3 to ethereum network using flutter?

查看:789
本文介绍了如何使用Flutter将Web3连接到以太坊网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting error while connecting with ethereum node.


  • 此行==> print(client.getBlockNumber() );返回错误


E / flutter(22015):[错误:flutter / lib / ui / ui_dart_state。 cc(148)]
未处理的异常:SocketException:主机查找失败:
'localhost:8545'(操作系统错误:没有与主机名相关的地址,错误号errno
= 7)

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());
    }
}


推荐答案

端口当您在本地以太坊区块链网络上进行开发时,通常使用Localhost上的8545。在这种情况下,最可能的原因是您没有在要进行注入的地方运行诸如Ganache之类的Client或Wallet服务。
Ganache创建了一个本地钱包,并为您提供了10个可以使用的开发Eth Address。您可以在您的应用程序中使用它。您的RPC端口是8545。

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.

这篇关于如何使用Flutter将Web3连接到以太坊网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆