Skip to content

ethers randomBytes() function and MaxUint256 constant equivalent #667

Answered by jxom
Melancholism asked this question in Question
Discussion options

You must be logged in to vote

In the context of viem, bytes are represented as a Uint8Array, so getRandomValues() would probably fit a bit better. You can do something like:

import { bytesToHex } from 'viem'

const randomBytes = crypto.getRandomValues(new Uint8Array(32))
const randomHexValue = bytesToHex(randomBytes)

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jxom
Comment options

jxom Jun 8, 2023
Maintainer

Answer selected by Melancholism
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants