0

I npm installed everything, yet only web3 is not working? Is this a bug or is there an alternative to this solution?

 import React,{useEffect, useState}from 'react';
    import { Connection, PublicKey,Account } from '@solana/web3.js';
    import { MintLayout, TOKEN_PROGRAM_ID, Token } from '@solana/spl-token';
    import { Program, Provider } from '@project-serum/anchor';
    
    import { sendTransactions } from './connection';
    import './CandyMachine.css';

Error message below

export 'web3' (imported as 'web3') was not found in '@solana/web3.js' (possible exports: Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction)
TylerH
  • 20,799
  • 66
  • 75
  • 101
slim.syd
  • 25
  • 2
  • 5

3 Answers3

0

actually you dont have to call web3 because you already imported Connection, PublicKey, Account directly.

example:

import { Connection, PublicKey } from '@solana/web3.js';

// Create new connection
const connection = new Connection(
   web3.clusterApiUrl('devnet'),
   'confirmed',
);

// Generate a new random public key
const somePublicKey = new PublicKey("someBase58AddressXxxXXXx2323")

if you want to call web3, your import should could be look like below:

import * as web3 from '@solana/web3.js';

// Create new connection
const connection = new web3.Connection(
   web3.clusterApiUrl('devnet'),
   'confirmed',
);

// Generate a new random public key
const somePublicKey = new web3.PublicKey("someBase58AddressXxxXXXx2323")

// etc
kafinsalim
  • 435
  • 6
  • 15
0

Error is clear. @solana/web3.js has no web3 to be exported. If you want to connect

import * as anchor from '@project-serum/anchor';
import { clusterApiUrl } from '@solana/web3.js';

const rpcHost =https://api.devnet.solana.com

const connection = new anchor.web3.Connection(rpcHost
  ? rpcHost
  : anchor.web3.clusterApiUrl('devnet'));
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
0

If you are working on VS Code, then after installaing web3 via pip, just restart the VS Code editor. It will then find Web3.

Be careful about below line:

from web3 import Web3  <- Small and Capital 'W'

Again, installing web3 requires Visual Studio Build Tools to be installed

Mahbub Rahman
  • 1,295
  • 1
  • 24
  • 44