Error: Socket Exception while trying to access kmd

Goodmorning everyone,
I am developing an Algorand Wallet on a Flutter mobile application in dart.
Right now I’m trying to connect to the kmd service of a node in order to get more addresses for a wallet from the same seedphrease.
The node has started and kmd also but when I try to use the algorithm library method.kmd I get an error like:

DioError [DioErrorType.other]: SocketException: OS Error: Connection refused, errno = 111, address = 127.0.0.1, port = 44824
# 0

below I attach the code that reports this error every time the algorithm.kmd.createWallet () method is presented :

Future<String> createNewAddress() async {

    final walletRequest = (CreateWalletRequestBuilder()
      ..walletName = 'wallet'
      ..walletPassword = 'test'
      ..walletDriverName = '')
        .build();

    final handleTokenRequest = (InitWalletHandleTokenRequestBuilder()
        ..walletId = 'wallet'
        ..walletPassword = 'test')
          .build();




    final keyRequest = (GenerateKeyRequestBuilder()
      ..displayMnemonic = true
      ..walletHandleToken = 'aa')
        .build();


      final response = await algorand.kmd.createWallet(createWalletRequest: walletRequest);

      final handleToken = await algorand.kmd.initWalletHandleToken(initializeWalletHandleTokenRequest: handleTokenRequest);

      final address = await algorand.kmd.generateKey(generateKeyRequest: keyRequest);

      return address.toString();
  }

would anyone know how to help me and explain why and how to fix this error? thanks a lot !

This is a duplicate of Connection refused, errno = 111, address = localhost, port = 57838 #0

As explained, doing that is very dangerous from a security point of view.
If you want to derive multiple accounts from the same passphrase, you need to implement the logic in the wallet itself and not rely on an external kmd which opens to a lot of attacks.

If you absolutely want kmd, the issue is most likely that:

  • the port is incorrect
  • or the address 127.0.0.1 is incorrect. Importantly, 127.0.0.1 means that kmd must be running on the same computer as the computer running the flutter app. iOS/Andoid simulator may be considered a different computer. And running the wallet as an iPhone/Android app on a real phone will never work with 127.0.0.1 because 127.0.0.1 is the local IP address of the phone that is not running kmd.
  • or kmd is not started properly (goal kmd start)

The error indeed indicate that the connection is refused, which usually means kmd is not running at 127.0.0.1:44824
If you are using sandbox, the port should be 4002.
Note that you can easily check whether kmd works on the above by using in command line:

 curl 127.0.0.1:44824/swagger.json

It should return a lot of lines of JSON.
If it does not the port or the address is not ok. Or kmd is not started.

PS: I would kindly ask you not to post again the same message. If you have a specific question after following any of the steps above (verifying address, port, kmd started, and running curl ...), please answer to this thread with the following information:

  • where is kmd running?
  • how did you install the Algorand software (sandbox, Debian package, …)?
  • where is the flutter app running?
  • what is the output of the above curl command?
  • how did you find the port 44824?

How can I implement this logic in the wallet itself, to be able to offer a multi wallet functionality and therefore derive multiple addresses from the same mnemonic without going through kmd?

One solution is to use BIP39.
You can see one implementation for Algorand there:

Disclaimer: I have nor reviewed this implementation. Algorand makes no representations regarding the functioning or security of wallets, exchanges, or tools mentioned in the answer above, and disclaims any liability therefor.

Right now my node is installed via sandbox and with the curl command 127.0.0.1:4002/swagger.json I get a response like:

{
  "consumes": [
    "application / json"
  ],
  "produces": [
    "application / json"
  ],
  "schemes": [
    "http"
  ],
  "swagger": "2.0",
  "Information": {
    "description": "API for KMD (key management daemon)",
    "title": "for the KMD HTTP API",
    "contact": {
      "e-mail": "contact@algorand.com"
    },
    "version": "0.0.1"
  },
  "host": "localhost",
  "basePath": "/",
  "paths": {
    "/swagger.json": {
      "get": {
        "description": "Returns the whole swagger specification in json.",
        "produces": [
          "application / json"
        ],
        "schemes": [
          "http"
        ],
        "summary": "Get the current swagger specification.",
        "operationId": "SwaggerHandler",
        "answers": {
          "200": {
            "description": "The current specifications of the swagger",
            "pattern": {
              "type": "string"
            }

to continue with all the methods of kmd…

my program is running on flutter and then on chrome at 127.0.0.1 and port 4001 but anyway I get an XMLHttpRequest error and I can’t continue, do you know how else to help me? thanks a lot

What do you mean by “running on flutter and then on chrome at 127.0.0.1 and port 4001”?
Port 4001 is for algod not kmd.

Can you also show the XMLHttpRequest error (copy-paste the exact error and also provide a screenshot as this can be helpful - screenshot including the address bar and the developer console with the error on the side).