Skip to content

How subscribe to balance changes? #445

Answered by raqeta
raqeta asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks to your help, chatGpt and official Polkadot.js documentation I find out everything work correct with this code :)

  final MyChainDot _myChainDot;
  final Map<String, StreamSubscription<StorageChangeSet>> _addressSubscriptionMap = {};

  @override
  Future<void> startBalanceListening(String? address, Function(BalanceData) onUpdate) async {
    if (address == null || address.isEmpty || _addressSubscriptionMap[address] != null) return;
    final accountPubKey = Address.decode(address).pubkey;
    final storageAccountKeyQuery = [_myChainDot.query.system.accountKey(accountPubKey)];
    _addressSubscriptionMap[address] = await _myChainDot.rpc.state.subscribeStorage(
      storageAccountK…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by leonardocustodio
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #385 on March 21, 2024 11:21.