Error object Object on runContractFunction(options)

After trying for a full day getting this to work, I couldnā€™t find any solutionā€¦
Below my code (Moralis @0.0.54):

var ABI4 = [{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"}];

var options = {
			  chain: "bsc",
			  address: "0x...",
			  name: "decimals",
			  abi: ABI4
			};

var decimals = await Moralis.Web3API.native.runContractFunction(options).catch(e => {
				console.log(e.message);
			});

I keep on getting the same ā€œobject Objectā€ error when the server sends back a error 400 with this response:

{"code":141,"error":"[object Object]"}

Logs Moralis Server:

2021-09-23T09:21:46.363Z - Error: [object Object]
    at fetch (/moralis-server/lib/cloud-code/plugins/convenience/web3Api.js:248:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
2021-09-23T09:21:46.359Z - Failed running cloud function runContractFunction for user X with:
  Input: {"chain":"bsc","address":"0x...","name":"decimals","abi":[{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"}]}
  Error: {"message":"[object Object]","code":141}

Am I doing something wrong?

Iā€™m also wondering if thereā€™s a possibility to add parameters to this function (since most of my contract functions needs added parameters).

Kind Regards

1 Like

Checking now, abi looks fine.

1 Like

This should work:

var options = {
			  chain: "bsc",
			  address: "0xe9e7cea3dedca5984780bafc599bd69add087d56",
			  function_name: "decimals",
			  abi: ABI4
			};

As in it should be function_name instead of name

1 Like

Yep, this works! Maybe update it in the docs? Cause there itā€™s still ā€œnameā€.
Is there also a possibility to add parameters to the function?

Kind regards and thanks for the help!

Yep, docs will have to be updated. I donā€™t think that this function supports parameters now.
You can use the web3 version for parameters for now.

What do you mean with the ā€œweb3 versionā€? Just web3.js?

Something similar to what you can see here:


but using call instead of send so that it doesnā€™t ask for gas

While this should work, the contract iā€™m using is on the bsc, not the eth chain.
I think thatā€™s why i get following errors?
Also when executing the .call() method, it still requires gas. I translated the decimals function into the ā€œweb3 versionā€.
See below for code and error.
Code:

const contract_address = "0x..."
			const web3 = await Moralis.Web3.enable();
			var ABI4 = [{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"}];
			let customToken = new web3.eth.Contract(ABI4, contract_address);
			let decimals = customToken.methods.decimals().call();

Error:

Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.

Maybe i should start a new thread tho :sweat_smile:

your code works fine if you change the network to bsc in metamaks

So thereā€™s no way I can get this to work with a wallet connected via WalletConnect?
Thanks for all the help btw

I think that you can init an web3 instance with a specific speedy node address.

1 Like

Perfect, thank you! Itā€™s all working now