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

Hi, here is a smart contract which has the multiple function definitions.

{
“inputs”: [
{
“internalType”: “address”,
“name”: “token”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
}
],
“name”: “deposit”,
“outputs”: [],
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “token”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “amount”,
“type”: “uint256”
},
{
“internalType”: “address”,
“name”: “to”,
“type”: “address”
}
],
“name”: “deposit”,
“outputs”: [],
“type”: “function”
}

1’st function - deposit(address token, unit256 amount)
2’nd function - deposit(address token, unint256 amount, address to)

then I call “deposit” function on frontend like this:

from<ObservableInput>(Moralis.executeFunction({
contractAddress: “0xxxxxxx”,
abi: xxx.abi,
functionName: ‘deposit’,
params: {
token: tokenAddress,
amount: amount,
to: userAddress
},
}));

then it returns this error:
“Multiple function definitions found in the abi. Please include the topic in the functionName.
Possible funcationNames: deposit(address,uint256) ,deposit(address,uint256,address)”

any solution?

did you try to include the topic in the function name?

thanks for your response.
sorry, but what is the topic?
instead of just calling ‘deposit’, I tried to call once more like this:
functionName: ‘deposit(address, unit256, address)’

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

Maybe because the function names are the same. try changing the function name and see if it works

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