0

I want to use web3.js together with my web page but the require function is not working for me. I have tried using browserify , importing instead of declaring as const but none worked, one problem solution lead to another problem. I tried to bundle these but web3 module has also some js inside which uses import statement so I am getting error to bundle them as well. issue while using web3js with require

simple js code

issue while using web3js with import

simple js code

  • Please boil down your problem to a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and share it as code, not pictures. – Antares42 Feb 08 '22 at 09:17
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 08 '22 at 09:18

1 Answers1

0

The import you wrote is wrong. Here are a few examples:

import {
  Keypair,
  AccountMeta,
  Connection,
  PublicKey,
  Transaction,
  TransactionInstruction,
  sendAndConfirmTransaction,
} from "@solana/web3.js";

Or

import web3 = require('@solana/web3.js');
Frank C.
  • 7,758
  • 4
  • 35
  • 45