Expected private key to be an Uint8Array with length 32
MetaNynja opened this issue · comments
I'm getting this error when I'm trying to deploy.
Error: Expected private key to be an Uint8Array with length 32
at assert (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\secp256k1\lib\index.js:18:20)
at isUint8Array (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\secp256k1\lib\index.js:31:7)
at Object.publicKeyCreate (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\secp256k1\lib\index.js:113:7)
at Object.exports.privateToPublic (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\node_modules\ethereumjs-util\src\account.ts:277:22)
at exports.privateToAddress (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\node_modules\ethereumjs-util\src\account.ts:285:26)
at LocalAccountsProvider._initializePrivateKeys (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\src\internal\core\providers\accounts.ts:183:43)
at new LocalAccountsProvider (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\src\internal\core\providers\accounts.ts:44:10)
at applyProviderWrappers (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\src\internal\core\providers\construction.ts:179:18)
at Object.createProvider (C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\src\internal\core\providers\construction.ts:117:27)
at C:\Users\User\V2 Smart Contract\poly-flash\node_modules\hardhat\src\internal\core\runtime-environment.ts:80:14
I have tried with and without the 0x on my private key. If I add the 0x in the .env then I can't compile, once I remove the 0x from the private key I am able to compile but I can't deploy due to error above.
Which kind of wallet are you using? What was the error message with deploying the contract with the 0x.
Can you try to deploy your contract on the mainnet fork with the following command ?
npx hardhat run scripts/deploy.ts
I was able to get it to deploy however I don't see it processed on my Metamask wallet.
This is what it showed after I deployed.
PS C:\Loan Contract\poly-flash> npx hardhat run scripts/deploy.ts
No need to generate any newer typings.
contract deployed to: 0xC1dC7a8379885676a6Ea08E67b7Defd9a235De71
Also note that I'm using Visual Studio Code. Same Node and Yarn versions that you're using.
The only way it would compile was by changing the hardhat config.
polygon: {
url: process.env.ALCHEMY_POLYGON_RPC_URL,
accounts: [0x${process.env.PRIVATE_KEY}
]
Changed to
polygon: {
url: process.env.ALCHEMY_POLYGON_RPC_URL,
accounts: [process.env.PRIVATE_KEY]
After I was only able to deploy it with npx hardhat run scripts/deploy.ts and not npx hardhat run scripts/deploy.ts --network polygon
However it deployed to is a Ropsten network when searching it, not the polygon network.
Wrong Readme about Private key
My bad. I added 0x
on hardhat.config.ts for metamusk users as you've showed, but if people follow the readme, I didn't have to do that.
I will change that. Thank you for pointing it out.
Deployed to a Wrong Network
Maybe your ALCHEMY_POLYGON_RPC_URL
is not for polygon. Make sure you get the polygon one from alchemy.
Thank you for your time, turns out I was making a very rookie mistake. I've got the contract to deploy!!