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.
Best Answer
When you directly use
ethers.providers.JsonRpcProvider()
, it tries to connect tolocalhost:8545
. Unless you are runningnpx hardhat node
, it would give you an error.Can you try using the 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?