I would like to use buffer library (in order handle binary data) in my website. here is my use case:
const privateKey = Buffer.from('<User's private key here>', 'hex');
buffer works fine in node.js without any additional npm module or script. but somehow,it is not working in web browser.it is showing an error
uncaught refernce error: buffer is not defined
I though we need to add library script file in our html file. please help me to fix this?
The Buffer object is only available in NodeJs and does not exist in the browser JS. But there is a script available that can be used available on GitHub.
Add standalone script to HTML from https://github.com/feross/buffer
<script src="https://bundle.run/[email protected]"></script>
Then in JS
const privateKey = buffer.Buffer.from(PRIVATE_KEY_1, "hex");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With