Trying to run contract functions on a different chain w/executeFunction()

Hi,
I’m trying to use Moralis.executeFunction(options); on a chain that’s not the current chain and it fails. Works if I change Metamask to the right chain. I can’t find that argument in the documentation but I see it is available on the MoralisWeb3.
Is there a way to specify the chain with Moralis.executeFunction() ?


options:
abi: [{…}]
chain: "0x4"
contractAddress: "0x9..."
functionName: "tokenURI"
params: {tokenId: '1'}

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. at 

Hey @niknak for Moralis.executeFunction to work you need to be on the right chain, there is no way to make transaction on different chain with web3 wallet interaction because you need to spend gas fees on the chain you desired.That is unless you would like to setup a relayer and web3 backend where there you can make transaction to any chain you want, but then you need you wallet to make the transaction instead of the users wallet.

Hope this helps~

1 Like

for read only functions you can use runContractFunction where you can specify the chain

@YosephKS Thanks for the answer. Sure I need it for gas transactions, but with this operation I’m only trying read from the chain.

Thanks @cryptokid I’ll try runContractFunction