patractlabs / redspot

Redspot is an Substrate pallet-contracts (ink!) development environment. Compile your contracts and run them on a different networks. Redspot's core forks from Hardhat but changed a lot to suit substrate.
https://redspot.patract.io/
Other
67 stars 22 forks source link

HDAccountsUserConfig support #157

Closed VargSupercolony closed 2 years ago

VargSupercolony commented 2 years ago

This PR aims to provide support for HDAccountsUserConfig, so that the user can derive multiple accounts from one seed (via provided derivation path).

ii-ii-ii commented 2 years ago

Thank you for your contribution.

But the HDAccounts one is an ethereum specification, not a polkadot one.

https://polkadot.js.org/docs/keyring/start/suri

In general the derivation format is specified as [//hard-derivation][/soft-derivation][///password] where

VargSupercolony commented 2 years ago

Well, I doubt it's Ethereum specific. Check this out: https://wiki.polkadot.network/docs/learn-accounts#derivation-paths image Polkadot.js, in fact, has .derive(suri, meta) method on KeyringPair, implying there is a way to derive one account from another using a derivation path. To me that is a kind of HD wallet implementation, just the derivation path format is different.

This change will allow users to manage a group of accounts (master, deployer, other deployment-related stuff) using a single mnemonic and a known derivation path, so as long as it makes sense - I think it's ok that Substrate does not explicitly implement this standard.

ii-ii-ii commented 2 years ago

Well, I doubt it's Ethereum specific. Check this out: https://wiki.polkadot.network/docs/learn-accounts#derivation-paths image Polkadot.js, in fact, has .derive(suri, meta) method on KeyringPair, implying there is a way to derive one account from another using a derivation path. To me that is a kind of HD wallet implementation, just the derivation path format is different.

This change will allow users to manage a group of accounts (master, deployer, other deployment-related stuff) using a single mnemonic and a known derivation path, so as long as it makes sense - I think it's ok that Substrate does not explicitly implement this standard.

Okay, whatever the spec is, I'd like to know what's the benefit of writing it like this. Why not use suri instead of object. Like:

"bottom drive obey lake curtain smoke basket hold race lonely fit walk//123/456"
VargSupercolony commented 2 years ago

The benefit is that with HDAccounts support, we can automatically derive child accounts from one master pair. This is useful because we always append the next child number to a derivation path, instead of coming up with our derivation path variants.

For me, three points:

  1. No possibility of human error when specifying child accounts (via derivation paths appended to the mnemonic)
  2. No need for a lot of env vars (for each account). Say we have four live networks, and for each network, we specify five accounts (one master and four children derived manually). That means setting 4 x 5 = 20 environment variables, which doesn't feel good. If we had HD wallets support, only 4 suris would be stored in the .env file.
  3. Better adoption for devs coming from Hardhat stack
VargSupercolony commented 2 years ago

Maybe I should add some docs?

ii-ii-ii commented 2 years ago

Maybe I should add some docs?

Yes, feel free to submit pr to improve the documentation. https://github.com/patractlabs/substrate-contracts-book