ethers randomBytes() function and MaxUint256 constant equivalent #667
-
What is the ethers randomBytes() function equivalent in viem? I also need to access the MaxUint256 constant like ethers here in viem. But the only constant that I can access in viem is the Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
You can use native Can look into exporting constants like that. As for now, might be worth just manually adding them yourself. |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering @jxom. import { randomBytes } from 'crypto';
const randomHexValue = `0x${randomBytes(32).toString('hex')}` And about the constants. I would really appreciate it if you could work on it and include them in viem like what ethers is doing. Also here is another discussion that asked for the same feature. Anyway, I will manually add them for now and wait for future releases. Thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
i've added all missing ethers-v5 and -v6 constants in this PR: #1475 |
Beta Was this translation helpful? Give feedback.
In the context of viem, bytes are represented as a
Uint8Array
, sogetRandomValues()
would probably fit a bit better. You can do something like: