Skip to content

new Wallet(privateKey) throws "invalid hexlify value" when privateKey is not 0x prefixed #1166

@matYang

Description

@matYang

While upgrading to Ethers V5, we ran into

Error: invalid hexlify value (argument="value", value="[not copied here]", code=INVALID_ARGUMENT, version=bytes/5.0.6)
I20201120-11:39:47.012(-5)?     at Logger.makeError (/Users/matthewyang/Desktop/blockchain/tokenfunder/tokenfunderapp/node_modules/@ethersproject/logger/src.ts/index.ts:205:28)
I20201120-11:39:47.013(-5)?     at Logger.throwError (/Users/matthewyang/Desktop/blockchain/tokenfunder/tokenfunderapp/node_modules/@ethersproject/logger/src.ts/index.ts:217:20)
I20201120-11:39:47.013(-5)?     at Logger.throwArgumentError (/Users/matthewyang/Desktop/blockchain/tokenfunder/tokenfunderapp/node_modules/@ethersproject/logger/src.ts/index.ts:221:21)
I20201120-11:39:47.013(-5)?     at Object.hexlify (/Users/matthewyang/Desktop/blockchain/tokenfunder/tokenfunderapp/node_modules/@ethersproject/bytes/src.ts/index.ts:242:19)
I20201120-11:39:47.013(-5)?     at new SigningKey (/Users/matthewyang/Desktop/blockchain/tokenfunder/tokenfunderapp/node_modules/@ethersproject/signing-key/src.ts/index.ts:35:44)
I20201120-11:39:47.032(-5)?     at new Wallet (/Users/matthewyang/Desktop/blockchain/tokenfunder/tokenfunderapp/node_modules/@ethersproject/wallet/src.ts/index.ts:81:36)

This issue was brought up in
https://www.gitmemory.com/issue/ethers-io/ethers.js/994/674504533

I assume this is not an intended feature, as all other tools accept non 0x prefixed private keys, and prefixing 0x to the private key causes issues with bunch of other libraries, so it's a change specific for Ethers V5

Regardless of it's intended or not, this should have been included in the breaking change log https://docs.ethers.io/v5/migration/ethers-v4/#migration-v4--contracts

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement.fixed/completeThis Bug is fixed or Enhancement is complete and published.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions