Wallet object? (BIP39 derived + HD capable) #189
-
The one thing I've found viem doesn't quite have yet is the concept of a Wallet like ethers does. There's a lot of reasons for first-class support of Wallets, the largest being that I foresee applications needing to integrate wallet capabilities and the interface to a user is generally a BIP39 mnemonic phrase. Seeing as the goal of viem is being a low-level Ethereum interface, I'd personally love to see first-class support for BIP39 wallets. Consider the example of sending a signed tx: in ethers: import { Wallet } from "ethers"
const provider = new providers.JsonRpcProvider(url, chainId)
const wallet = Wallet.fromPhrase("...", provider)
const receipt = await wallet.sendTransaction(...) in Viem, it would look something like this: const wallet = /* ??? */
const account = getAccount(wallet.address as `0x${string}`)
const client = createWalletClient({
key: wallet.privateKey,
transport: http(...)
})
const receipt = await client.sendTransaction(...) It's very clear from the docs how to create a wallet client, but it's not clear how to use a Wallet (phrase + HD path => pk) which was derived from a mnemonic and path. Is this out of scope for viem, or is this something you'd be open to accepting a PR for? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You are right that viem does not yet have first-class support for wallets & client-side signing. This is something we want to add in very soon (I am currently exploring some different options with WASM via ethers-rs (Rust), and pure JS via @noble/secp256k1, @scure/bip32 & @scure/bip39). Right now, if you want to use HD or private key wallets with viem, we have an adapter for an Ethers.js Wallet while you wait for us to provide first-class support for this. Will post an RFC in the GitHub discussions once we have a more concrete API (which will be soon), and then you can expect an implementation soon after that. We are definitely open to collaborating on an RFC + implementation, so if you're interested, reach out. |
Beta Was this translation helpful? Give feedback.
You are right that viem does not yet have first-class support for wallets & client-side signing. This is something we want to add in very soon (I am currently exploring some different options with WASM via ethers-rs (Rust), and pure JS via @noble/secp256k1, @scure/bip32 & @scure/bip39).
Right now, if you want to use HD or private key wallets with viem, we have an adapter for an Ethers.js Wallet while you wait for us to provide first-class support for this.
Will post an RFC in the GitHub discussions once we have a more concrete API (which will be soon), and then you can expect an implementation soon after that. We are definitely open to collaborating on an RFC + implementation, so if you'r…