zksync-sdk / zksync2-js

MIT License
25 stars 29 forks source link

Feature: Ledger support for the Wallet class #23

Open rareadam opened 9 months ago

rareadam commented 9 months ago

🌟 Feature Request

📝 Description

I'd like to see support for instantiating a Wallet that is backed by a ledger device. This could be done using a new static constructor like

static fromHardwareWallet(pubKey: string, provider?: ethers.Provider): Wallet

🤔 Rationale

In regular hardhat projects we can use @nomicfoundation/hardhat-ledger to add support for ledger devices and use it using the high level interface using ethers.getSigners() with something like this:

const [_, deployer] = await ethers.getSigners();
const MyContract = await ethers.getContractFactory('MyContract');
const myContract = await MyContract.connect(deployer).deploy();
await myContract.waitForDeployment();

Since we can't use this high level interface in zkSync deployments we rely on the Deployer class from this repo which is basically a nice wrapper around the Wallet class which by now only supports directly supplied key material.

Having an option to use a ledger here would be very appreciated

🖼️ Mockups/Examples

It would be nice if this here would work (the code is referencing the default deploy script from the project template used by zksync-dev create project foobar)

import { Wallet } from "zksync-web3";
import { deployContract } from "./utils";
export default async function () {
  const wallet = Wallet.fromHardwareWallet('0xdeadbeefdeadbeef') 
  const contractArtifactName = "Greeter";
  const constructorArguments = ["Hi there!"];
  await deployContract(contractArtifactName, constructorArguments, { wallet });
}