0

I added a new account using this command in PolkadotJS.

const { pair, json } = keyring.addUri(mnemonic, 'myStr0ngP@ssworD', { name: 'mnemonic acc' });

And now, I want to forget the account. I used keyring.forgetAddress, but it doesn't really remove the account. I always load accounts using keyring.getAccounts() after forgetAddress.

enter image description here

For example, how does the Forget Account action work in the PolkadotJS extension? What function or API is called? Please help me.

2 Answers 2

0

I believe the method to use here is forgetAccount, not forgetAddress.

5
  • Yes, you are right. Thank you very much.
    – INcre
    Commented Oct 20, 2022 at 20:11
  • @INcre Please, mark the question as resolved then. Commented Oct 24, 2022 at 7:35
  • I am not able to check two answers at once. Do you know how to do that? @Adam
    – INcre
    Commented Oct 24, 2022 at 16:38
  • Ah, ok, I missed Bruno's answer. Nevermind then. Commented Oct 25, 2022 at 8:16
  • Thank you. Your answer is very helpful!!!
    – INcre
    Commented Oct 25, 2022 at 11:24
1

Exactly what Adam said.

According to the docs:

forgetAddress mirrors forgetAccount and if we look in the code we will see the minor difference in the two:

  public forgetAddress (address: string): void {
    this.addresses.remove(this._store, address);
  }
  public forgetAccount (address: string): void {
    this.keyring.removePair(address);
    this.accounts.remove(this._store, address);
  }

The reason you are still seeing the account when you call getAccounts is because forgetAddress() does not call this.accounts.remove(this._store, address) where as forgetAccount() does.

1
  • Yes, you are right. Thank you very much. @Bruno
    – INcre
    Commented Oct 20, 2022 at 20:13

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.