0

I'm using OpenZeppelin's upgradeable contracts with its hardhat-ethers plugin and typechain plugin. However, I keep getting an error Expected private key to be an Uint8Array when I run the deployment.

Here's what I have for my deployment script:

import { providers } from "ethers";
import { ethers, upgrades } from "hardhat";

const provider = new providers.JsonRpcProvider();
const signer = provider.getSigner();

// Information about the signer does get logged out correctly
console.log(signer);

const factory = await ethers.getContractFactory('MyContract', signer)
await upgrades.deployProxy(factory);

When I console log the signer, it's information is logged out correctly, which I presume it means the signer information did get passed into the getContractFactory.

I'm running this in Jest. I'm not running this through hardhat test since this particular script isn't really a test but a deployment script that I plan to eventually use and I want to write a test for it. Unless the hardhat test has some magic injected when running, I don't see how different it would be when I run it like a regular nodejs script.

Why does it keep complaining that the private key needs to be an Uint8Array? I don't see how else I can pass any private key from the signer into the functions.

1 Answer 1

0

When you directly use ethers.providers.JsonRpcProvider(), it tries to connect to localhost:8545. Unless you are running npx hardhat node, it would give you an error.

Can you try using the provider from hardhat?

import { ethers, upgrades } from "hardhat";

const provider = ethers.provider; // using provider from hardhat

Also private key needs to be an Uint8Array is a weird error. Is it possible for you to include the error in your question?

2
  • If the JsonRpcProvider is connecting to localhost, by using the provider from hardhat, ethers.provider, where would it actually be connecting?
    – xenon
    Aug 23, 2021 at 15:37
  • It generates an in-memory provider, more efficient, as it directly uses the EthereumJS APIs instead of exposing a JSON RPC server and serving requests from that. Aug 25, 2021 at 18:25

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.