I am getting this error: Error: transaction.chainId/signature.v mismatch
From this code:
const { LedgerSigner } = require('@ethersproject/hardware-wallets')
async function main () {
const signer = new LedgerSigner(ethers.provider)
const usdcAddress = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'
// account 3
const account3 = 'myaddress'
const erc20 = (await ethers.getContractAt('IERC20', usdcAddress)).connect(signer)
const tx = await erc20.transfer(account3, ethers.utils.parseUnits('0.1', 6))
const receipt = await tx.wait()
if (receipt.status) {
console.log('Successful')
} else {
console.log('Failed')
}
}
The v value for the signature is 54.
I wonder if this error could be related to the chain id math change that was made in ledgerjs: https://github.com/LedgerHQ/ledgerjs/commit/a1f21d25f3c216d4b2ec475c0802c56223e9a9e0
This code is using Hardhat connected to Polygon, which uses chainId 137.
Please help me get this fixed. Thanks!
Yeah, the Ledger code was doing the math wrong for higher chain ids before. The Ledger library needs to be bumped for Ethers to fix this.
Yeah, the Ledger code was doing the math wrong for higher chain ids before. The Ledger library needs to be bumped for Ethers to fix this.
I confirmed this is true. I cloned ethers.js and updated the ledger libraries and now it works.
Good to know. Were there any other changes needed other than changing the package name?
No, only change was using the latest versions of the ledgerjs libraries. I made a pull request if that is helpful: https://github.com/ethers-io/ethers.js/pull/1370
Oh, I see. Pulling in a deprecated version, which I assume is one they maintain for backwards compatibility.
I can probable merge that change sooner then. I need to finish off Typed Transactions first, then I should be able to pull that in.
Great.
Can this be merged soon? I have someone else that needs this to work with Polygon. Thanks
Is this coming soon?
I鈥檝e been working on it straight for the last few days, the changes are not trivial to get things properly up to date. Please a bit more patience. :)
Oh, that is really great, good job, and so much very appreciated! Sorry about being demanding.
I am curious, with this merge request it has been working for me. Of course I like and appreciate it being better and streamlined. I am curious, what you are improving?
The main thing is to pull the ancillary packages from the monorepo, especially things like the hardware wallets package, which have incredibly complex dependencies (it needs an OS with the dev libusb, and/or hid headers, and C extensions). They are causing havoc with the CI environments, and even testing locally is non-trivial.
I鈥檓 trying to upgrade the LedgerSigner to use modern methods of communicating from both node and the browser instead of the hacky u2f hijacking they used to do, which they have deprecated.
Right now I鈥檓 still fighting the dist file generation, as the Ledger libraries don鈥檛 seem to play nice with bundlers, but I think a module that can be dropped into a web browser will simplify the lives for many (including myself ;)).
Yes, makes sense. I think it is really great you are doing this. I think LedgerSigner is critically important software so it thrills me to see you doing this.
A module that can be dropped into a web browser will simplify the lives for many (including myself ;)).
This sounds really great.
How would developers and users use this module in a web browser? What would be the user flow?
Would it work like this:
Right now people can use Ledger with MetaMask. But it isn't so great because there is a really annoying persistent security popup that comes up anytime someone tries to make a transaction with Ledger on Windows 10. Can the new Ledger support you are working on be a good alternative solution?
How is the new Ledger support coming along?
Most helpful comment
The main thing is to pull the ancillary packages from the monorepo, especially things like the hardware wallets package, which have incredibly complex dependencies (it needs an OS with the dev libusb, and/or hid headers, and C extensions). They are causing havoc with the CI environments, and even testing locally is non-trivial.
I鈥檓 trying to upgrade the LedgerSigner to use modern methods of communicating from both node and the browser instead of the hacky u2f hijacking they used to do, which they have deprecated.
Right now I鈥檓 still fighting the dist file generation, as the Ledger libraries don鈥檛 seem to play nice with bundlers, but I think a module that can be dropped into a web browser will simplify the lives for many (including myself ;)).