0

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]?

1

1 Answer 1

0

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

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.