I am writing a Hardhat task. Hardhat ethers provides ethers.getSigners()which returns me the addresses derived from the mnemonics saved in process.env.

However, I want to use an account address, of which I have the private key only and would like to import that account, use it as signers for the contract calls and get the address.

How can I achieve that?

In the task, currently signers[0]is used as signer. How could I switch to signers[1]?


2 Answers 2


this works for me using ethers.js

import { Signer, Wallet } from 'ethers';
const provider = hre.ethers.provider;
const privKey = process.env['PRIVATE_KEY'];
const signer_wallet = new Wallet(privKey);
const signer = await signer_wallet.connect(provider);

Once you have your signer you can use it to deploy contracts or connect to existing ones


Update your hardhat.config.js

module.exports = {
  networks: {
    sepolia: {
      url: "https://sepolia.infura.io/v3/<key>",
      accounts: [private_key, private_key,...] // compatible with your `signers[0], signers[1]`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.