I've been messing around for a while with the @solana/web3.js browser bundle (https://docs.solana.com/developing/clients/javascript-api#bundle) and I'm having some difficulty sending a transaction. My current code utilizes the sendAndConfirmTransaction
method, but I'm seeing the following error:
ReferenceError: Buffer is not defined
at toBufferLE (browser.js:48:24)
at bigIntLayout.encode (bigint.ts:30:19)
at Structure.encode (Layout.js:1092:36)
at encodeData (instruction.ts:32:15)
at SystemProgram.transfer (system.ts:796:14)
at sendTransaction ((index):88:36)
at async Proxy.submitData ((index):65:9)
Below is the function I'm currently working with.
async function sendTransaction() {
console.log('Sending transaction...')
try {
const keypair = await solanaWeb3.Keypair;
let transaction = new solanaWeb3.Transaction();
let connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl("devnet"));
transaction.add(
solanaWeb3.SystemProgram.transfer({
fromPubkey: keypair.publicKey,
toPubkey: keypair.publicKey,
lamports: solanaWeb3.LAMPORTS_PER_SOL,
}),
);
solanaWeb3.sendAndConfirmTransaction(connection, transaction, [keypair]);
} catch (error) {
console.log(error)
}
}
I've read that Buffer is not available in the latest builds of the web3.js library, but the only answers I've seen are related to Webpack updates. I'm assuming I'm missing a dependency? Any insight is greatly appreciated. Thanks!