[SOLVED] Moralis.executeFunction doesn't find correct one in the multiple-defined functions

the topic is the function name and with the parameter types, like deposit(address,uint256,address) is a topic

for a fast fix you can rename in the abi one of the functions to deposit2 and it should work fine

you can also try exactly with the topic for function name, without spaces

1 Like

Thank you, cryptokid.
but unfortunately, deposit(address,uint256,address) (without spaces as your idea) doesn’t work properly and I get this error.

Function with the provided topic does not exist in abi. Possible funcationNames: deposit(address,uint256) ,deposit(address,uint256,address)

BTW I don’t want to fix that issue by modifying function name in abi

What version of Moralis sdk are you using?

I think that this was somehow fixed in an update

This is called function overloading

FYI, the way the contract knows what function you’re calling is that it uses a function selector . The function selector is the first four bytes of every transaction you send to a contract, and those are the first four bytes of the keccak256 hash of the function signature.

Check the link for more info
https://docs.soliditylang.org/en/v0.8.13/contracts.html

1 Like

Check this thread:

I use moralis v1.3.5

that’s just one way I used.
const sendOptions = {
contractAddress: “0xxxx”,
abi: xxx.abi,
functionName: ‘deposit(address,unit256,address)’,
params: {
token: tokenAddress,
amount: amount,
to: userAddress
}
};

then call a function as follows:
Moralis.executeFunction(sendOptions)

but I get this error:
Function with the provided topic does not exist in abi. Possible funcationNames: deposit(address,uint256) ,deposit(address,uint256,address)

that’s really out of my head and I am getting headache with this simple issue.
it might work in multiple definition function like other lang but don’t make sense why.

It looks like this was the comment that adds that functionality:

Thanks for information.
I updated moralis from 1.3.5 to 1.5.5(latest one) but same error still.

Can you paste a minimal complete code that doesn’t work?

Like the part of the abi that contains those two functions

I posted my problem with ABI at the first time.

And here are two functions from front-end.

deposit(tokenAddress: string, amount: BigNumber, userAddress: string) {
const sendOptions: executeFunctionOptions = {
contractAddress: “0xxxx”,
abi: xxx.abi,
functionName: ‘deposit(address,unit256,address)’,
params: {
token: tokenAddress,
amount: amount,
to: userAddress
}
};
return from(Moralis.enableWeb3()).pipe(
concatMap(() => {
return from<ObservableInput>(Moralis.executeFunction(sendOptions));
})
);
}

depositAvax(amount: BigNumber) {
return from(Moralis.enableWeb3()).pipe(
concatMap(() => {
return from<ObservableInput>(Moralis.executeFunction({
contractAddress: “0xxxx”,
abi: xxx.abi,
functionName: ‘deposit’,
msgValue: amount.toString()
}));
})
);
}

Here it looks like it uses only deposit, but maybe you didn’t call this function

sorry, I don’t make senes what you mean.

In the code that you pasted, there are different formats when you call those two functions, one with topic and one with function name.

I can test later to see what happens.
You can also look here to see how to post code on forum: READ BEFORE POSTING - How to post code in the forum

this is the first time to use this forum and sorry for an inconvenience.
Here are original codes.

deposit(tokenAddress: string, amount: BigNumber, userAddress: string) {
    return from(Moralis.Web3.enableWeb3()).pipe(
      concatNetworkVerification(),
      concatMap(() => {
        return from<ObservableInput<any>>(Moralis.Web3.executeFunction({
          contractAddress: "0xxx",
          abi: xxx.abi,
          functionName: 'deposit',
          params: {
            token: tokenAddress,
            amount: amount,
            to: userAddress
          },
        }));
      })
    );
  }

  depositAvax(amount: BigNumber) {
    return from(Moralis.Web3.enableWeb3()).pipe(
      concatNetworkVerification(),
      concatMap(() => {
        return from<ObservableInput<any>>(Moralis.Web3.executeFunction({
          contractAddress: "0xxxx",
          abi: xxx.abi,
          functionName: 'deposit',
          msgValue: amount.toString()
        }));
      })
    );
  }

Since it didn’t work properly I have made some modifications so that it gets fixed.

1 Like

I’ll get back to you in 1-2 hours after I test it

it looks like the problem was this typo with unit256 instead of uint256

3 Likes

wow, actually.
I was so stupid. because the function with topic was written in “”, the compiler didn’t notice it’s just error.
it’s fixed now and it works well.
Thank you very much for your help.

1 Like