ABIDefinedFunction - ARitz-Cracker/arc-web3 GitHub Wiki

EthereumContracts will be created with all methods defined in the ABI.

For example, consider this solidity contract

contract C{
    function test() public pure returns (uint8){
        return 8;
    }
}

In javascript...

await C.test(); // 8

If 2 functions exist with the same name, the library will try to figure out which function to use with the types given.

Solidity:

contract C{
    function test(uint8) public pure returns (uint8){
        return 8;
    }
    function test(string) public pure returns (uint8){
        return 4;
    }
}

JavaScript:

await C.test(8); // 8
await C.test("8"); // 4
await C.test() // Error: Expected 1 argument.

However, there are cases where the function to use cannot be determined. In JavaScript, an array can contain any type. If the array is empty, there's no way to determine the type of the objects in the array. When ambiguity like this occurs, it's best to select the function using its name and argument types.

Solidity:

contract C{
    function test(uint8[]) public pure returns (uint8){
        return 8;
    }
    function test(string[]) public pure returns (uint8){
        return 4;
    }
}

JavaScript:

await C.test([8]); // 8
await C.test(["8","8"]); // 4
await C.test([]) // Error: Unable to determine which function to use with the given arguments.
await C["test(uint8[])"]([]) // 8
await C["test(string[])"]([]) // 4