'SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 52035

I am having a flutter app, and want to connect it with ganache for ether transfer. But when I connect it with my real device it has given me the following error.

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 127.0.0.1, port = 52035

String rpcUrl = "http://127.0.0.1:7545";
  String wsUrl = "ws://127.0.0.1:7545/";

  sendEther() async {
    Web3Client client = Web3Client(rpcUrl, Client(), socketConnector: () {
      return IOWebSocketChannel.connect(wsUrl).cast<String>();
    });

    String privateKey =
        "cce548f8263f25d63613bb48b87391b9c83f07a3ede4a5f8380549f93c2ca05f";

    Credentials credentials =
        await client.credentialsFromPrivateKey(privateKey);

    EthereumAddress ownAddress = await credentials.extractAddress();
    EthereumAddress reciever =
        EthereumAddress.fromHex("0x3B0ae8eecdFe232b453Ea107B65B2B7FFE8d46B9");
    print("#################");
    print(ownAddress);

    client.sendTransaction(
        credentials,
        Transaction(
          from: ownAddress,
          to: reciever,
          value: EtherAmount.fromUnitAndValue(EtherUnit.ether, 1)
        ));
  }

This is my code to send ether to another account.

Ganache localhost RPC SERVER "HTTP://127.0.0.1:7545". How to work it on real device?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source