feature(`cast`): extend `cast wallet list` or add a new command to support deriving accounts from a mnemonic
Component
Cast
Describe the feature you would like
Description
cast wallet list currently lists accounts stored in the keystore directory, but there is no built-in way to list derived accounts from a given mnemonic. For debugging and development workflows, it would be helpful to generate and inspect multiple addresses (and optionally private keys) directly from a mnemonic.
Current workaround:
MNEMONIC="code code code code code code code code code code code quality"
ACCOUNTS=3
for i in $(seq 1 $ACCOUNTS); do
pk=$(cast wallet private-key --mnemonic "$MNEMONIC" --mnemonic-index "$((i - 1))")
address=$(cast wallet address --private-key "$pk")
echo '{"address":"'$address'","private_key":"'$pk'"}'
done | jq --slurp
which produces:
[
{
"address": "0x85dA99c8a7C2C95964c8EfD687E95E632Fc533D6",
"private_key": "0x42b6e34dc21598a807dc19d7784c71b2a7a01f6480dc6f58258f78e539f1a1fa"
},
{
"address": "0x125FB391bA829e0865963D3B91711610049a9e78",
"private_key": "0x0903a9a721167e2abaa0a33553cbeb209dc9300d28e4e4d6d2fac2452f93e357"
},
{
"address": "0x964ec59D0E05Db08440c822d7C588e63BBDE8c4e",
"private_key": "0x6421222a9964cbe1b411191dcac1afda173ed99346c47302c6fe88f65d83583e"
}
]
Proposed Enhancement
Extend the existing cast wallet list or introduce a new subcommand, for example:
cast wallet list --mnemonic "<mnemonic>" --accounts N
By default, it would only output addresses, for security reasons. It could take an optional flag, --insecure, to also include the corresponding private keys.
If the maintainers consider this feature useful, I’d be happy to work on the implementation! :)
Additional context
No response
Hey @leovct
Good idea! I think a cast wallet derive utility would be more appropriate here as what you are doing is deriving from a mnemonic
--list is really meant more for listing a collection of wallets
This would be useful! Instead of adding a new cast wallet derive command, could we add this to the existing cast wallet private-key with a few optional params like --accounts 3 --start-index 2 ?
Can you assign it to me? I could work on this.