Error: Socket Exception while trying to access kmd - General - Algorand

Error: Socket Exception while trying to access kmd

post by simospa on Oct 6, 2021

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 seedphrase.

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 !

post by fabrice on Oct 6, 2021

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 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:

post by simospa on Oct 6, 2021

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?

post by fabrice on Oct 6, 2021

One solution is to use BIP39.

You can see one implementation for Algorand there:

Disclaimer: I have not 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.

post by simospa on Oct 8, 2021

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

post by fabrice on Oct 8, 2021

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).