Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the callback issue encountered by nodejs when using @ polkadot/API #5783

Closed
HanSXY opened this issue Jan 17, 2024 · 2 comments
Closed

Comments

@HanSXY
Copy link

HanSXY commented Jan 17, 2024

Using nodejs to call @ polkadot/API version "^ 10.11.1"

There were some occasional issues during use, please refer to the following code snippet

import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';
const api = await ApiPromise.create();
await api.tx.utility
  .batch(Array)
  .signAndSend( accountFromKeyring, async ( { events = [], status , dispatchError  } ) => {
    if (status.isInBlock) {
      console.log('number1');
      events.forEach( async ({ event: { method, data: [error] } }) => {
        if (method == 'BatchInterrupted') {
          console.log('number2');
        } else if(method == 'BatchCompleted'){
          console.log('number3');
        }
      });
    }
  })

In the above code execution, I can obtain the print log of number1, but sometimes I cannot obtain the print log of number2 or number3. Is there a problem with my writing style?

@TarikGul
Copy link
Member

This could be because you aren't covering all the events that could possibly happen.

utility: {
/**
* Batch of dispatches completed fully with no error.
**/
BatchCompleted: AugmentedEvent<ApiType, []>;
/**
* Batch of dispatches completed but has errors.
**/
BatchCompletedWithErrors: AugmentedEvent<ApiType, []>;
/**
* Batch of dispatches did not complete fully. Index of first failing dispatch given, as
* well as the error.
**/
BatchInterrupted: AugmentedEvent<ApiType, [index: u32, error: SpRuntimeDispatchError], { index: u32, error: SpRuntimeDispatchError }>;

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants