Comments (14)
I found the problem. In ganache, in the setting, the server's host name is 127.0.0.0 initially, I switch to 0.0.0.0 and it works well!!! Probably, for geth node, the problem is rpcdomain property.
Thank you so much! Finally, I spend a whole night to solve this problem.
from web3dart.
Right, but the Android emulator will also setup a virtual network, so you can't reach your host through 0.0.0.0
. You can use 10.0.2.2
though, as explained here.
from web3dart.
No, it wouldn't work on a real device. In that case you'd have to lookup the IP address of the host. Inside your local network it probably starts with 192.168
, so you could use that address for devices inside your local network.
from web3dart.
var privatekey = '0x6166244d506a4c1635e0a0723cda3780fa80462a869682xxxxxxxxxx';
var apiUrl = "http://10.0.0.47:8545"; //Replace with your API
var httpClient = new Client();
var ethClient = new Web3Client(apiUrl, httpClient);
// String data = await DefaultAssetBundle.of(context).loadString(
// "assets/web3/8acd17e6f4fef86fdf75078d179ec2612fb354ae.json");
// final jsonResult = json.encode(data);
// Wallet wallet = Wallet.fromJson(data, "aa");
var credentials = Credentials.fromPrivateKeyHex(privatekey);
// Credentials unlocked = wallet.credentials;
EtherAmount balance = await ethClient.getBalance(credentials.address);
print(balance.getValueInUnit(EtherUnit.ether));
I tried to use both methods. It didn't work.
from web3dart.
If you try something like
var httpClient = new Client();
await httpClient.get('$apiUrl/');
before starting your ethClient
. Does that also throw the exception?
If so, you might be missing the internet permission in your Flutter app. Maybe this helps?
from web3dart.
If you try something like
var httpClient = new Client(); await httpClient.get('$apiUrl/');before starting your
ethClient
. Does that also throw the exception?
If so, you might be missing the internet permission in your Flutter app. Maybe this helps?
It doesn't help when I add await httpClient.get('$apiUrl/');, the same exception.
This time I deployed my smart contract on ganache, when I tried to connect, it shows the same exception.
Could it be a problem with MacOS? Do I need to switch to Linux to deploy my smart contract?
from web3dart.
I don't think it's an issue with your operating system. Rather, the error indicates that your Flutter app is unable to reach the network.
Are you on Android? If so, try adding <uses-permission android:name="android.permission.INTERNET" />
to the AndroidManifest.xml
in the android/app
folder of your Flutter project.
from web3dart.
I have already added the permission long long ago, the app can access the Internet well.
Do I need to provide other environment information?
from web3dart.
Hm, that's really weird.
But just to be sure, if you remove the web3dart
related code of that snippet entirely and just try to make a request with the http
package like this:
import "package:http/http.dart" as http;
await http.get("http://10.0.0.47:8545");
You do get the same problem, right?
I don't really get how your app can access the internet while still getting connection errors in web3dart
. This library delegates all the work to the Client()
, which is part of the http
package. If you're making http requests elsewhere in your app, you're probably already using that package. It's weird how that works while there are errors in web3dart
.
I'm not really familiar with MacOS unfortunately. I might be that there is a firewall blocking that port, even from the local network?
from web3dart.
Hm, that's really weird.
But just to be sure, if you remove theweb3dart
related code of that snippet entirely and just try to make a request with thehttp
package like this:import "package:http/http.dart" as http; await http.get("http://10.0.0.47:8545");You do get the same problem, right?
I don't really get how your app can access the internet while still getting connection errors in
web3dart
. This library delegates all the work to theClient()
, which is part of thehttp
package. If you're making http requests elsewhere in your app, you're probably already using that package. It's weird how that works while there are errors inweb3dart
.I'm not really familiar with MacOS unfortunately. I might be that there is a firewall blocking that port, even from the local network?
I do have these permissions, like:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.hardware.location.gps" /> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
So, that's why confusing. I will try to use http tomorrow. Thank you, I will let you know.
from web3dart.
@simolus3 @liuyuejiang I am running into a very similar issue... In my case, my app runs fine on an ios simulator, but on an actual android device/emulator, it gives out E/flutter ( 6625): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = 0.0.0.0, port = 51300
, and I have added in the permission for android to access internet.
When I opened the dart dev tool, in the Network tab, the ws and http methods both showed pending.
Any help is appreciated...
from web3dart.
Why would you connect to 0.0.0.0
? Surely there's no Ethereum node running on the actual emulator?
from web3dart.
Why would you connect to
0.0.0.0
? Surely there's no Ethereum node running on the actual emulator?
Thank you sir for your quick reply. I used Ganache and I changed the server hostname to 0.0.0.0 - all interfaces
from web3dart.
Right, but the Android emulator will also setup a virtual network, so you can't reach your host through
0.0.0.0
. You can use10.0.2.2
though, as explained here.
Yes sir, It did work. Thank you! One more question, how about a real android device? Will it work with 10.0.2.2
Ganache?
from web3dart.
Related Issues (20)
- NFT dapp HOT 1
- How to set a timeout for Web3Client? HOT 1
- intToBytes mistake
- How to decodeParameters
- web3dart
- Ignore non_constant_identifier_names, camel_case_types in generated (.g.dart) files HOT 5
- Test Net HOT 2
- Support ethers.utils functionality HOT 1
- Bug: Zero address returned from contract call causes exception HOT 20
- web3dart: ^2.3.3
- private Api for centralized blockchain HOT 3
- How can i call smart contract functions through web3dart without private key in flutter HOT 2
- getBlockInformation() - Throws Error HOT 1
- Transaction Lists HOT 2
- How a new user can create an account without private key?
- Support for BEP20 Transfer?
- Value not in Range
- On Ganache V 7.0.0 I am receiving an rpc error "Unhandled Exception: RPCError: got code -32700 with msg "Invalid signature v value"." HOT 1
- Getting transactions with eth_getBlockByNumber
- Doesn't work after building project but works fine in debug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web3dart.