Home
Support Forums

Web3 function works locally but not on deployed site

Site: flamboyant-yonath-8e978f

I have a ‘approve’ function using Web3. It works fine locally, but when I try on the deployed site, I get a “Uncaught (in promise) Error: invalid BigNumber value” error.

My local uses node version 14.5.4, so I tried setting the env variable to that, but that still didn’t work.

The function itself is straightforward:

const amount = new BigNumber(2**255)
console.log(amount)
const request = await props.sendJustContract.methods.approve(address, amount).send({from: props.account});

When I log the BigNumber it’s the exact same on local and deploy. Yet I still get the error

Functions use a different variable. You need to set AWS_LAMBDA_JS_RUNTIME to nodejs14.x. That x need not be changed to any number. Just use the value as it is.

About the actual error. What library are you using that’s giving you new BigNumber()? I’m asking so I can try this myself.

bignumber.js (bignumber.js API)

I tried what you said, but it still didn’t work. Do I need to redeploy after changing the env? Should I try redeploying and clearing the cache? Should I remove the previous env variable?

Yes, you do need to re-deploy. Clearing cache won’t be needed, but it can help. Previous variable can stay there.

Redeploying didn’t help

Could you share the repo?

I’m unable to get the error as I’m not sure what this line is doing props.sendJustContract.methods.approve(address, amount).send({from: props.account});

I believe that’s the one throwing the error in your case?

Sure, what’s your github email/username?

You could add Hrishikesh-K to the repo.