transform from ethereumjs-util keccak256 to ethers.js keccak256
See original GitHub issuestatic combinedHash(first: Buffer, second: Buffer): Buffer {
if (!first) {
return second
}
if (!second) {
return first
}
return keccak256(MerkleTree.sortAndConcat(first, second))
}
This is what I am using with ethereumjs-util's keccak256. All seems well and it’s working, but the idea is that keccak256 returns Buffer , so that’s why I have Buffer as returned type for combinedHash function. All works.
Now I want to get rid of ethereumjs-utils and use ethers.js’s keccak256. So I do this, but ,the problem arises.
- The first problem is that i can’t pass
Buffertokeccak256 - The second problem is it returns string instead of Buffer. If I try to transform the returned data into buffer by myself with
Buffer.from, it produces the different buffer and my tests start to fail.
How can I fix those ? Any help would be appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to use ethers keccak256? - Ethereum Stack Exchange
With ethers.js v5 you can use: const { ethers, utils } = require("ethers"); const labelhash = utils.keccak256(utils.toUtf8Bytes("example")).
Read more >Documentation - Ethers.js
sendTransaction({ to: "ricmoo.firefly.eth", value: ethers.utils. ... and is computed by normalizing the Event signature and taking the keccak256 hash of it.
Read more >Hashing Algorithms - ethers
The Ethereum Identity function computes the KECCAK256 hash of the text bytes. ... convert strings to bytes first: utils.keccak256(utils.
Read more >ethereumjs-util keccak256 TypeScript Examples
This page shows TypeScript code examples of ethereumjs-util keccak256. ... 0, 20)); // Fail if bytecode is still not valid hex after transformations...
Read more >How do I match ecrecover in ethers and in Solidity? · Issue #468
I have the following code in an Angular app: ethers.Wallet. ... payload); let payloadHash = ethers.utils.keccak256(payload); ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I fixed it…
I think I was missing
arrayifyin the middle.This is what made it work:
Thanks a lot for all the help , especially this quick.
Best of luck.
Oh. Is that being returned from a function? I think it’s complaining about the return type from your function, not ethers. You need to either specify your function returns a string, or use
Buffer.from(arrayify(v)), maybe?