leonardocustodio / polkadart

Polkadart provides developers the ability to query a node and interact with the Polkadot based chains using Dart.
https://polkadart.dev
Apache License 2.0
39 stars 16 forks source link

type 'Id' is not a subtype of type 'MultiAddress' #400

Closed web3-sante closed 9 months ago

web3-sante commented 10 months ago

Hello !

What could be the reason for this error. I tried to connect to a Substrate node based on the substrate Node template.

On Dart side I tried to run the example based on the generated files from the Substrate Node template

Example of dart the binary file for my generated files after running the polkadart_cli command but I got the error

type 'Id' is not a subtype of type 'MultiAddress'.

The files are correctly generated and the example with Polkadot chain worked fine but for the substrate node template that's the error I got.

Here are the versions of polkadart, cli, ... on pubspec file


  polkadart: ^0.3.1
  polkadart_keyring: ^0.3.0
  polkadart_cli: ^0.3.1

here is the link of the gist dart file used to interact with the node.

leonardocustodio commented 10 months ago

Hello @web3-sante,

The types are generated by polkadart-cli from the chain metadata. Meaning they can change depending on the network you are running against (what features/pallets/rpc it has). I've never run it on the substrate node template but it seems the MultiAddress on it has a different format.

You can easily check the available types with the IDE autocomplete by typing:

MultiAddress.values.

image

Btw, you can also create the MultiAddress using the format above instead of using $MultiAddress. Let me know if this helps or not.

web3-sante commented 10 months ago

Thanks @leonardocustodio for the feedback.

For now I do not have any pallet configured just the default pallets configured on the node template.

The values are pretty much the same as what you get by doing autocomplete..

Capture d’écran 2024-01-27 à 11 47 46
leonardocustodio commented 10 months ago

Interesting, it could be a bug after all. I will run a template node and check it out later today.

web3-sante commented 10 months ago

Interesting, it could be a bug after all. I will run a template node and check it out later today.

yup sounds good

leonardocustodio commented 9 months ago

Interesting, I've just run a template node here and it worked fine. Did you add the node in the pubspec.yaml file? And have run the dart run polkadart_cli:generate -v after it?

polkadart:
  output_dir: lib/generated
  chains:
    polkadot: ws://127.0.0.1:9944
web3-sante commented 9 months ago

Interesting, I've just run a template node here and it worked fine. Did you add the node in the pubspec.yaml file? And have run the dart run polkadart_cli:generate -v after it?

polkadart:
  output_dir: lib/generated
  chains:
    polkadot: ws://127.0.0.1:9944

Yes I have done that, all the files are generated correctly but the problem comes when try to run the examples in the gist file. To be exact at this part:

 final publicKey = hex.encode(keyring.publicKey.bytes);
 print('Public Key: $publicKey');
 final dest = $MultiAddress().id(hex.decode(publicKey));
 final runtimeCall = api.tx.balances.transferAll(dest: dest, keepAlive: true);
 print('Runtime call: $runtimeCall');
leonardocustodio commented 9 months ago

I understand but that's the thing, I copied and pasted your gist, generated the types against a fresh template node, ran the code, and it worked fine

Public Key: d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db3221
Runtime call: Instance of 'Balances'
Encoded call: 040400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db322101
Payload: 040400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db322101050100006400000001000000d0eb2aa35f6bb55176c5043d62d9b50f3a5472aa87c5af7dafd70ae58a4bc69d6a0ef5be5af855f584711acc60008f8bb73ab8a2a2c01de73c731b642797f36d
Signature: 38cc3b12ec95f8305d0974fb10af86c9c1a480aa346bb04abd8633100c14c149dd8868376091eeea65e8513104c11e389a84b5b3beb7ca3a3af02b453417f284
Extrinsic: 2d028400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db32210138cc3b12ec95f8305d0974fb10af86c9c1a480aa346bb04abd8633100c14c149dd8868376091eeea65e8513104c11e389a84b5b3beb7ca3a3af02b453417f28405010000040400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db322101
Unhandled exception:
Exception: {code: 1010, message: Invalid Transaction, data: Inability to pay some fees (e.g. account balance too low)}

Are you sure your import is correct? The only thing I changed in the gist was the imports as I generated with another name, but it seems to be the same as yours:

import 'package:polkadart_example/generated/polkadot/polkadot.dart';
import 'package:polkadart_example/generated/polkadot/types/sp_runtime/multiaddress/multi_address.dart';

Maybe you could be using an older version of the packages? Try running: dart pub upgrade and try deleting the lib/generated folder before generating the types just in case.

web3-sante commented 9 months ago

I understand but that's the thing, I copied and pasted your gist, generated the types against a fresh template node, ran the code, and it worked fine

Public Key: d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db3221
Runtime call: Instance of 'Balances'
Encoded call: 040400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db322101
Payload: 040400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db322101050100006400000001000000d0eb2aa35f6bb55176c5043d62d9b50f3a5472aa87c5af7dafd70ae58a4bc69d6a0ef5be5af855f584711acc60008f8bb73ab8a2a2c01de73c731b642797f36d
Signature: 38cc3b12ec95f8305d0974fb10af86c9c1a480aa346bb04abd8633100c14c149dd8868376091eeea65e8513104c11e389a84b5b3beb7ca3a3af02b453417f284
Extrinsic: 2d028400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db32210138cc3b12ec95f8305d0974fb10af86c9c1a480aa346bb04abd8633100c14c149dd8868376091eeea65e8513104c11e389a84b5b3beb7ca3a3af02b453417f28405010000040400d0c5fca112207646534d8a8896f0e7ba6711b5e82e761320f09c7bf249db322101
Unhandled exception:
Exception: {code: 1010, message: Invalid Transaction, data: Inability to pay some fees (e.g. account balance too low)}

Are you sure your import is correct? The only thing I changed in the gist was the imports as I generated with another name, but it seems to be the same as yours:

import 'package:polkadart_example/generated/polkadot/polkadot.dart';
import 'package:polkadart_example/generated/polkadot/types/sp_runtime/multiaddress/multi_address.dart';

Maybe you could be using an older version of the packages? Try running: dart pub upgrade and try deleting the lib/generated folder before generating the types just in case.

Alright ! Let me try to upgrade versions

web3-sante commented 9 months ago

@leonardocustodio Indeed. I suspect the reason was the fact that the polkadart and polkadart_cli packages used were not the latest. I was testing it on 2 projects and one got old versions I don't know how ☹️.

  polkadart: ^0.2.6
  polkadart_keyring: ^0.2.1
  polkadart_cli: ^0.2.4

But Now it works!

Thank you for the support 👍