Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: failed to get balance of account TypeError: fetch failed #35460

Closed
yarcowang opened this issue Mar 19, 2024 · 1 comment
Closed

Error: failed to get balance of account TypeError: fetch failed #35460

yarcowang opened this issue Mar 19, 2024 · 1 comment
Labels
community Community contribution

Comments

@yarcowang
Copy link

Problem

Hello, guys, I'm trying following the tutorial https://www.soldev.app/course/intro-to-reading-data.
But such code doesn't work

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

const connection = new Connection(clusterApiUrl("devnet"));
const address = new PublicKey('CenYq6bDRB7p73EjsPEpiYN7uveyPUTdXkDkgUduboaN');
const balance = await connection.getBalance(address);

console.log(`The balance of the account at ${address} is ${balance} lamports`); 
console.log(`✅ Finished!`)

It will result:

yarco@heaven scripts$ HTTPS_PROXY=http://127.0.0.1:7890 npx esrun key_001.ts 
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
(node:55856) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
/Users/yarco/Documents/Workspace/Blockchain/solana/scripts/node_modules/.pnpm/@[email protected]/node_modules/@solana/web3.js/src/connection.ts:3245
        throw new Error(
              ^


Error: failed to get balance of account CenYq6bDRB7p73EjsPEpiYN7uveyPUTdXkDkgUduboaN: TypeError: fetch failed
    at e (/Users/yarco/Documents/Workspace/Blockchain/solana/scripts/node_modules/.pnpm/@[email protected]/node_modules/@solana/web3.js/src/connection.ts:3245:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Connection.getBalance (/Users/yarco/Documents/Workspace/Blockchain/solana/scripts/node_modules/.pnpm/@[email protected]/node_modules/@solana/web3.js/src/connection.ts:3242:12)
    at async file:///Users/yarco/Documents/Workspace/Blockchain/solana/scripts/[eval1]:13:15

Node.js v21.7.1

There's also such question in solana.stackexchange.com , but got no answer.

I'm pretty sure it is not networking problem, because the axios answer axios to another question in stackoverflow.com does work.

Check my running result:
scripts_—_-bash_—_159×49

So, maybe something wrong in web3.js? bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?) ?
(I've also tried downgrade the node to v18, still the same error)

Proposed Solution

For now only the axios version: https://stackoverflow.com/a/77715282/1960612
does work to me.

Mac m1 pro
Node: v21.7.1 (also tried v18)
pnpm: 8.15.5

@solana-developers/helpers 2.1.0
@solana/web3.js 1.91.1
axios 1.6.8
bigint-buffer 1.1.5
dotenv 16.4.5
esrun 3.2.26
typescript 5.4.2

@yarcowang yarcowang added the community Community contribution label Mar 19, 2024
Copy link
Contributor

This repository is no longer in use. Please re-open this issue in the agave repo: https://github.com/anza-xyz/agave

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution
Projects
None yet
Development

No branches or pull requests

1 participant