Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating new Wallet instance #3768

Closed
mhughdo opened this issue Feb 13, 2023 · 6 comments
Closed

Error creating new Wallet instance #3768

mhughdo opened this issue Feb 13, 2023 · 6 comments
Assignees
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6

Comments

@mhughdo
Copy link

mhughdo commented Feb 13, 2023

Ethers Version

6.0.2

Search Terms

wallet, invalid BytesLike value

Describe the Problem

I couldn't create a new instance of Wallet using ethers v6.0.2, whereas I could do it using ethers v5.4.0.

Expect:
image

Actual:
image

Code Snippet

import dotenv from 'dotenv'
import {ethers, Wallet} from 'ethers'
dotenv.config()

const {PRIVATE_KEY} = process.env
let WSSUrl = ''
let provider = new ethers.WebSocketProvider(WSSUrl)

let account = new Wallet(PRIVATE_KEY, provider)

console.log(account.address)

Contract ABI

No response

Errors

TypeError: invalid BytesLike value (argument="value", value="valid private key", code=INVALID_ARGUMENT, version=6.0.2)

Environment

node.js (older than v12)

Environment (Other)

Node.js v18.14.0

@mhughdo mhughdo added the investigate Under investigation and may be a bug. label Feb 13, 2023
@mhughdo
Copy link
Author

mhughdo commented Feb 13, 2023

After reading the source code, I realized I must prefix the private key with "0x". Ethers v5 does the prefixing automatically.
Maybe you should update the document to include this change.

@ricmoo
Copy link
Member

ricmoo commented Feb 13, 2023

I was debating whether to re-introduce that functionality. I really want to force people to include a 0x prefix, but I believe there is a popular piece of software that spits out keys without it. I have to look through my notes and figure out which software and if it is better now. :)

@mhughdo
Copy link
Author

mhughdo commented Feb 13, 2023

Thank you for your reply. In my case, I'm using Metamask, and it's still exporting the private key without the 0x prefix.

@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6 and removed investigate Under investigation and may be a bug. labels Feb 13, 2023
@ricmoo
Copy link
Member

ricmoo commented Feb 13, 2023

Ah yes... I think it was because of MetaMask. I'll re-add support.

Thanks!

@mhughdo
Copy link
Author

mhughdo commented Feb 14, 2023

Thank you. It'll be very helpful

@ricmoo
Copy link
Member

ricmoo commented Feb 19, 2023

Added in v6.0.5. Let me know if you still have any issues.

Thanks! :)

@ricmoo ricmoo closed this as completed Feb 19, 2023
@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants