magic-js icon indicating copy to clipboard operation
magic-js copied to clipboard

Insufficient funds for gas * price + value"}, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS

Open phil3k3 opened this issue 2 years ago • 2 comments

✅ Prerequisites

  • [x] Did you perform a cursory search of open issues? Is this bug already reported elsewhere?
  • [x] Are you running the latest SDK version?
  • [x] Are you reporting to the correct repository (magic-sdk)?

🐛 Description

I am receiving INSUFFICIENT_FUNDS when trying to use the signer of Magic's RPC provider.

Magic RPC Error: [-32603] Error forwarded from node: insufficient funds for gas * price + value"}, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS

🧩 Steps to Reproduce

  1. Create sample project as described in https://magic.link/docs/dedicated/login-methods/email/integration/web
  2. Generate a Web3Provider using ethers v5 const owner = new ethers.providers.Web3Provider(magic.rpcProvider as any);
  3. Use the signer of this provider to retrieve the balance of an ERC 20 token
const contract = new ethers.Contract(tokenAddress, erc20Abi, owner.getSigner());
const balance = await contract.balanceOf(receiver);

🤔 Expected behavior

Getting the balance of this usually gas-less transaction.

😮 Actual behavior

"Magic RPC Error: [-32603] Error forwarded from node: insufficient funds for gas * price + value"}, method="sendTransaction", transaction=undefined, code=INSUFFICIENT_FUNDS

💻 Code Sample

[If possible, please provide a code repository, gist, code snippet or sample files to reproduce the issue.]

🌎 Environment

Software Version(s)
magic-sdk 21.0.0
Browser Chrome
yarn 1.22.19
Operating System MacOS 13.4.1

phil3k3 avatar Oct 25 '23 09:10 phil3k3

Hello @phil3k3 ,

The error you shared should throw when you attempt to send a transaction or interact with a smart contract but don't have enough native token balance to cover the cost of the interaction. It should not throw for a contract interaction that is just reading state, because there is no fee for reading the contract state.

Would you be able to provide a reproducible code sandbox where this issue is reproduced? If not, do you have steps for us to follow to reproduce this issue?

I created a sandbox here that makes a call to the Uniswap contract to get the balance of an account. The call properly returns even with a new user wallet because balanceOf is a view function and does not require gas. You may fork the demo to reproduce your issue.

Thank you,

am-hernandez avatar Dec 12 '23 00:12 am-hernandez