I have an issue regarding displaying errors. For errors, the logger @polkadot/api uses will write to console even when the error is caught and handled. I am handling and displaying the messages a certain way to fit my needs but then I recieve two errors, one I created and one from the @polkadot/api . I am using HttpProvider instead of WsProvider. Is there a way to suppress @polkadot/api messages?

this.provider = ApiPromise.create({ provider: httpProvider, noInitWarn: true });

This is the provider initialization which is in the class constructor.

try {
    this.provider = await this.provider;
    const nonce = await this.provider.rpc.system.accountNextIndex(address);
    return nonce;
catch (e) {

I am creating a separate class methods in which I make requests to the node. In the perfect case scenario after receiving an error I would like to handle it on my own without being displayed in the console.

Best regards!

1 Answer 1


You should be able to trap the provider and api errors, and then do nothing with them...

const provider = new WsProvider('wss://rpc.polkadot.io');
// events: connected, disconnected, error
provider.on('error', (err) => {
  // console.error(err)

const api = await ApiPromise.create({ provider });
// events: connected, disconnected, error, decorated, ready
api.on('error', (err) =>{
  // console.error(err)
  • I am not using WebSocket as a provider, instead I use HttpProvider. Commented Dec 7, 2022 at 15:03
  • perhaps if you share some of your code we can help you better
    – DerekC
    Commented Dec 8, 2022 at 16:10
  • 1
    Please put any code examples in the original message. That way you can use code formatting and it's easier to see. Anyway, the HttpProvider has no api.on() event, so you can't trap it. Are you able to switch to a WsProvider?
    – DerekC
    Commented Dec 12, 2022 at 8:39
  • I've updated the original message. Unfortunately I cannot use WsProvider, because in my use case it is unreliable. Commented Dec 12, 2022 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.