【发布时间】:2023-02-03 00:02:44
【问题描述】:
在创建一个简单的程序时,我无法让 Solana 使用 devnet 进行 RPC 连接。我不断收到以下错误:
{
blockhash: '7TTVjRKApwAqP1SA7vZ2tQHuh6QbnToSmVUA9kc7amEY',
lastValidBlockHeight: 129662699
}
Error: failed to get recent blockhash: FetchError: request to http://localhost:8899/ failed, reason: connect ECONNREFUSED 127.0.0.1:8899
at Connection.getRecentBlockhash (/home/simeon/dev/freelance/niels_vacancies/node_modules/@solana/web3.js/lib/index.cjs.js:6584:13)
即使我已经设置了所有可设置的常量,如 ANCHOR_PROVIDER_URL=https://api.devnet.solana.com,或我的 Anchor.toml 文件中的相关条目。我还明确指定以下内容:
const connection = new anchor.web3.Connection("https://api.devnet.solana.com/", {commitment: "max"});
const wallet = anchor.Wallet.local();
const provider = new anchor.Provider(
connection,
wallet,
{
commitment: "max",
preflightCommitment: "max",
skipPreflight: false
}
)
我什至测试了console.log(await anchor.getProvider().connection.getLatestBlockhash());,以确保我实际上可以从 devnet 获取区块哈希。我可以做些什么来强制 RPC 调用也这样做?
【问题讨论】:
-
您的 solana cli 配置(solana config get)是什么?您可以更改它:solana config set --url devnet
标签: solana anchor-solana