1

As the title suggests, I need to make an AWS Lambda function which retrieves an account balance.

Tha problem is that it often throws the error:

INFO    Error: failed to get balance of account 4pZWvfQZWAYDxMCoGhMhySURo3JCriXB2CUUqhXyKF1H: TypeError: fetch failed
    at /opt/nodejs/node_modules/@solana/web3.js/lib/index.cjs.js:6006:13
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at runNextTicks (node:internal/process/task_queues:64:3)
    at process.processImmediate (node:internal/timers:449:9)
    at async Connection.getBalance (/opt/nodejs/node_modules/@solana/web3.js/lib/index.cjs.js:6005:12)
    at async /var/task/bot.js:43:30
    at async execute (/opt/nodejs/node_modules/telegraf/lib/composer.js:501:17)
    at async /opt/nodejs/node_modules/telegraf/lib/composer.js:502:21
    at async execute (/opt/nodejs/node_modules/telegraf/lib/composer.js:501:17)
    at async /opt/nodejs/node_modules/telegraf/lib/composer.js:502:21
2024-02-10T13:05:21.558Z 7429f075-092d-4bbe-8dbf-7de887ef3e55 INFO Error: failed to get balance of account 4pZWvfQZWAYDxMCoGhMhySURo3JCriXB2CUUqhXyKF1H: TypeError: fetch failed at /opt/nodejs/node_modules/@solana/web3.js/lib/index.cjs.js:6006:13 at processTicksAndRejections (node:internal/process/task_queues:95:5) at runNextTicks (node:internal/process/task_queues:64:3) at process.processImmediate (node:internal/timers:449:9) at async Connection.getBalance (/opt/nodejs/node_modules/@solana/web3.js/lib/index.cjs.js:6005:12) at async /var/task/bot.js:43:30 at async execute (/opt/nodejs/node_modules/telegraf/lib/composer.js:501:17) at async /opt/nodejs/node_modules/telegraf/lib/composer.js:502:21 at async execute (/opt/nodejs/node_modules/telegraf/lib/composer.js:501:17) at async /opt/nodejs/node_modules/telegraf/lib/composer.js:502:21

This is the simple line which is raising the error:

const balance = (await new Connection(process.env.SOLANA_HTTPS).getBalance(new PublicKey("4pZWvfQZWAYDxMCoGhMhySURo3JCriXB2CUUqhXyKF1H"))) / 10**9;

I'm stuck on this and I cannot get the problem with AWS Lambda. Locally, it works great!

Thank you in advance

1
  • 1
    The error is not really Solana specific. It means either you have network issue or nodejs verson issue. Are you sure you are using the latest Node.js version which supports fetch? Also, make sure your network and firewall settings allow requests. You can test it out by making a simply GET request to any public API. Feb 17 at 16:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.