Connection refused, errno = 111, address = localhost, port = 57838 #0

Hello everyone, I am developing an application on Flutter in dart on Android Studio, using an external API with all the package of Algorand and kmd. When I use the kmd method to create a new wallet I get this error:

DioError [DioErrorType.other]: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 57838

Below I am attaching the code relating to the above error. Whenever I try to access the createWallet () function it shows up.

Future<String> createNewAddress() async {

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

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

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

      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? Thank you !

What external API are you using?

If you are not running your own node, chances are the kmd API is not enabled.
If you are running your own node, you need to start the kmd API: goal kmd start.

Hi, this is the API I am using: GitHub - RootSoft/algorand-dart: Unofficial community SDK to interact with the Algorand network, for Dart & Flutter
the application I am developing on android studio with flutter in Dart, no I am not currently using any node for testing. I usually use docker sandbox for nodes, do you know a way to interface it in this case with a type of application like this?

If you are using Sandbox, the port should be 4002 not 57838.
See GitHub - algorand/sandbox: Algorand node sandbox

Can you show the code of CreateWalletRequestBuilder()?

Also, the use of kmd is very limited.
Most dApps should use AlgoSigner (AlgoSigner | Algorand Wallet Extension for Chrome | PureStake), MyAlgoConnect (Introducing MyAlgo Connect for DApp Developers | Algorand Developer Portal), or WalletConnect (WalletConnect - Algorand Developer Portal).

sorry for the duplication, I was looking for an answer …
My intent is to derive multiple addresses from the same seedphrase, so kmd seemed the most suitable way to do this, am I wrong?
where can I also change the port number to use?

This is the code of the CreateWalletRequestBuilder class:

class CreateWalletRequestBuilder
    implements Builder<CreateWalletRequest, CreateWalletRequestBuilder> {
  _$CreateWalletRequest? _$v;

  ListBuilder<int>? _masterDerivationKey;
  ListBuilder<int> get masterDerivationKey =>
      _$this._masterDerivationKey ??= new ListBuilder<int>();
  set masterDerivationKey(ListBuilder<int>? masterDerivationKey) =>
      _$this._masterDerivationKey = masterDerivationKey;

  String? _walletDriverName;
  String? get walletDriverName => _$this._walletDriverName;
  set walletDriverName(String? walletDriverName) =>
      _$this._walletDriverName = walletDriverName;

  String? _walletName;
  String? get walletName => _$this._walletName;
  set walletName(String? walletName) => _$this._walletName = walletName;

  String? _walletPassword;
  String? get walletPassword => _$this._walletPassword;
  set walletPassword(String? walletPassword) =>
      _$this._walletPassword = walletPassword;

  CreateWalletRequestBuilder() {

  CreateWalletRequestBuilder get _$this {
    final $v = _$v;
    if ($v != null) {
      _masterDerivationKey = $v.masterDerivationKey?.toBuilder();
      _walletDriverName = $v.walletDriverName;
      _walletName = $v.walletName;
      _walletPassword = $v.walletPassword;
      _$v = null;
    return this;

  void replace(CreateWalletRequest other) {
    ArgumentError.checkNotNull(other, 'other');
    _$v = other as _$CreateWalletRequest;

  void update(void Function(CreateWalletRequestBuilder)? updates) {
    if (updates != null) updates(this);

  _$CreateWalletRequest build() {
    _$CreateWalletRequest _$result;
    try {
      _$result = _$v ??
          new _$CreateWalletRequest._(
              masterDerivationKey: _masterDerivationKey?.build(),
              walletDriverName: walletDriverName,
              walletName: walletName,
              walletPassword: walletPassword);
    } catch (_) {
      late String _$failedField;
      try {
        _$failedField = 'masterDerivationKey';
      } catch (e) {
        throw new BuiltValueNestedFieldError(
            'CreateWalletRequest', _$failedField, e.toString());
    return _$result;

Is your app a wallet?
If not, we highly recommend you to look at the options above.
Storing passphrases / accounts is extremely complex and require having a very strong background in security.

In particular, if the passphrase is held by the user, you should NOT use KMD to derive accounts. This is highly dangerous and insecure. If your backend gets compromised, all your users accounts get compromised!

Passphrases held by users MUST not leave the device.
And once again, unless you are writing a wallet, I strongly discourage you from trying to store any passphrase on an app, but instead you should use MyAlgoConnect, AlgoSigner (only desktop), WalletConnect.

my application is a wallet, everything works correctly and I have already developed the secure local archiving of the seedphrase.
But what I’m trying to do now is to develop a feature that allows wallet users to create a multi-wallet wallet, with different addresses but linked to the same seedphrase.