Skip to content

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

Closed
@HanSXY

Description

@HanSXY

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions