I want to sign some view transactions in frontend using a random keypair instead of wallet provider like phantom or solflare to avoid Approve popup

I tried to create wallet like this:

import { Wallet } from '@project-serum/anchor'
import { Keypair } from '@solana/web3.js'

const wallet1 = new Wallet(Keypair.generate())

But I got this error:

TypeError: _project_serum_anchor__WEBPACK_IMPORTED_MODULE_7__.Wallet is not a constructor

1 Answer 1

import NodeWallet from '@project-serum/anchor/dist/cjs/nodewallet'
let wallet = new NodeWallet(Keypair.generate())
  • Got this error in NextJS when used tried NodeWallet: ./node_modules/@project-serum/anchor/dist/cjs/nodewallet.js:17:0 Module not found: Can't resolve 'fs' Import trace for requested module: ./pages/timer.tsx https://nextjs.org/docs/messages/module-not-found Oct 10, 2022 at 14:07

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .