Solana buffer not defined

I wanna send a transaction. Buffer isn’t drfi ied though. I am using the browser solana bundle.

I used bundlify to bundle it. Still same error

Can you post in code how you’re using Solana? Are you on the latest Moralis SDK?

For Buffer is not defined these links may help:

Uncaught ReferenceError: Buffer is not defined · Issue #1626 · evanw/esbuild (

node.js - Uncaught ReferenceError: Buffer is not defined - Stack Overflow

Hi Impare,

You are getting this error since you are using the browser bundle given by Solana. The browser bundle does not contain all the dependencies required for running the Solana/web3js module.

You have to install the dependencies by yourself.

This is how I solved it:

Install Solana npm module

$ npm i @solana/web3.js

Create a js file called “solanaWeb3js-input.js”

The file contains:
var solanaWeb3 = require('@solana/web3.js');

Browserify the file

Install browserify if you haven’t. Use this command to browserify and bundle up the “solanaWeb3js-input.js” file:

browserify -r @solana/web3.js -s solanaWeb3 -o solanaWeb3.browser.js

Place the “solanaWeb3.browser.js” file in a script tag in your code and you’re good to go.


1 Like