1

I am getting this error when trying to link a smart contract deployed on a Ganache local blockchain with Flutter web3dart package.

Note: Testing on android (both emulator and physical device give the same error)

E/flutter ( 5780): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled
Exception: Connection refused
E/flutter ( 5780): #0      IOClient.send (package:http/src/io_client.dart:88:7)
E/flutter ( 5780): <asynchronous suspension>
E/flutter ( 5780): #1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:32)
E/flutter ( 5780): <asynchronous suspension>
E/flutter ( 5780): #2      JsonRPC.call (package:web3dart/json_rpc.dart:49:22)
E/flutter ( 5780): <asynchronous suspension>
E/flutter ( 5780): #3      Web3Client._makeRPCCall (package:web3dart/src/core/client.dart:53:20)
E/flutter ( 5780): <asynchronous suspension>
E/flutter ( 5780): #4      ContractLinker.initialSetup (package:cupcake_eth2/contract_linking.dart:60:16)
E/flutter ( 5780): <asynchronous suspension>
E/flutter ( 5780): #5      ContractLinker.contractLinking (package:cupcake_eth2/contract_linking.dart:44:5)
E/flutter ( 5780): <asynchronous suspension>
E/flutter ( 5780): #6      ContractLinker.onInit (package:cupcake_eth2/contract_linking.dart:16:5)
E/flutter ( 5780): <asynchronous suspension>

Here are my variables:

 final String _rpcUrl = "http://127.0.0.1:7545";
 final String _wsUrl = "ws://127.0.0.1:7545/";

Relevant part of truffle_config.js:

networks: {
     development: {
      host: "127.0.0.1",
      port: 7545,           
      network_id: "*",       
     },
  },

I am following this tutorial

Any help is greatly appreciated.

1 Answer 1

0

Add

  final String _rpcUrl =
      Platform.isAndroid ? 'http://10.0.2.2:7545' : 'http://127.0.0.1:7545';
  final String _wsUrl =
      Platform.isAndroid ? 'http://10.0.2.2:7545' : 'ws://127.0.0.1:7545';

instead of

final String _rpcUrl = "http://127.0.0.1:7545";
final String _wsUrl = "ws://127.0.0.1:7545/";
2
  • What is this ? What is that ? How does it solve the problem ? May 2, 2023 at 11:20
  • Check it again i have changed the answer May 2, 2023 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.