找不到导入web3..在solana web3.js中



我npm安装了所有东西,但只有web3不工作?这是一个错误还是有替代方案?

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';

下方的错误消息

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)

实际上您不必调用web3,因为您已经直接导入了Connection, PublicKey, Account

示例:

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")

如果你想调用web3,你的导入应该如下所示:

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

错误很明显。@solana/web3.js没有要导出的web3。如果你想连接

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'));

如果您正在处理VS Code,那么在通过pip安装web3之后,只需重新启动VS Code编辑器。然后它会找到Web3。

小心下面的行:

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

同样,安装web3需要安装Visual Studio构建工具

相关内容

  • 没有找到相关文章

最新更新