Cloud functions - using bignumber on mainnet and testnet

Hi,

I have 2 servers, 1 on mainnet and 1 on testnet and use the same cloud functions on both to test them

I am using web3 on cloud functions just for bignumber and nothing else

but if I use a mainnet chainId then I get {code: 141, error: ā€œCould not find providerā€} error on testnet version

const web3 = Moralis.web3ByChain(ā€œ0x38ā€);
const BN = web3.utils.BN;

yes it’s possible to upload different versions for both of them but I’m using the same codebase from cli so it’s easier to use exact same and not change it on every upload

is it possible to use bignumbers without choosing a target chain id? or is it possible to get the current server details on cloud functions so I can assign a testnet chainId or mainnet chainId depending on the current server dynamically?

Thanks

I believe we have Moralis.Cloud.BigNumber you don’t need to choose the chain for that

awesome, didnt see it on the docs
thanks

1 Like

It returns undefined for me when using Moralis.Cloud.BigNumber do I need to initialize something first?

did you try something like this: number = new Moralis.Cloud.BigNumber(+value)?

Oh I assumed it’s an injected library.

I used Moralis.Cloud.BigNumber.from() and it complained about Moralis.Cloud.BigNumber being undefined and undefined not have a function from. So just logging logger.info(JSON.stringify(Moralis.Cloud.BigNumber)) returns undefined on my end.

I use Moralis.Cloud.ethersByChain("0x38").ethers.utils.parseUnit(valueAsString, decimal) and I defined it as a constant function const toBn = (value, decimal) => ...(valueAsString,decimal) in the cloud function to cascade the complexity :laughing: