Get the number of accounts derived for a wallet #2818
-
Is there a way to get the number of accounts derived for a wallet in ethers? But is there a way to keep track of the index so that every time the wallet is accessed, the accounts can be listed and switched between, similar to how metamask displays the list of accounts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That is something that requires state, like a file or lock storage, which is not built into ethers as state is application and domain specific. You will need to manually track that data somewhere that makes sense for your application. NetaMask uses the plug-in container local storage for their purpose. In a more generic sense, when importing a mnemonic, most software will scan a “gap” (which I think is commonly 40?). This is to find and addresses in use, searching until there are at least GAP unused addresses. This software will also not usually allow creating new unused accounts past GAP too, to ensure future imports would work as expected. |
Beta Was this translation helpful? Give feedback.
That is something that requires state, like a file or lock storage, which is not built into ethers as state is application and domain specific.
You will need to manually track that data somewhere that makes sense for your application.
NetaMask uses the plug-in container local storage for their purpose.
In a more generic sense, when importing a mnemonic, most software will scan a “gap” (which I think is commonly 40?). This is to find and addresses in use, searching until there are at least GAP unused addresses. This software will also not usually allow creating new unused accounts past GAP too, to ensure future imports would work as expected.