0

I have a method :

function getBalance(address _add) public view 
            returns (uint256, string memory, bool, uint256, uint256, uint256) {
        return(accountBalance[_add].amount,
            accountBalance[_add].valueDateTime,
            accountBalance[_add].credit,
            accountBalance[_add].bankId,
            accountBalance[_add].branchId,
            accountBalance[_add].accountId);
    }

I have tried many ways to get some hash which will work for my json rpc. But I am not able to get through. Tried combinations which didn't work :

web3.sha3('getBalance(address) returns (uint256, string,bool,uint256,uint256,uint256)'); "0x2560a3f9b1f28442f55de402532d55bffa0794ee53310ed4dc65d3dda6a8fc4b"

web3.sha3('getBalance(address) returns (uint256, string memory,bool,uint256,uint256,uint256)'); "0x963fc1d2d6f67d205b9f56340f6f9853ea45969dcc25182fbd9705abe74cfcbf"

web3.sha3('getBalance(address) view returns (uint256, string memory,bool,uint256,uint256,uint256)'); "0xdcd78e55620fe9302439c2ccb0c23d69f7399b61e3b0b6c9c15142f85fe6b3fa"

web3.sha3('getBalance(address) view returns (uint256,string,bool,uint256,uint256,uint256)'); "0x97abd19f4ac051fb6b277f2c947801a9120e0935a7225ff322d1cf2a2dcb1b8a"

web3.sha3('getBalance(address) view returns (uint256,string memory,bool,uint256,uint256,uint256)'); "0xc174d458674c0f18ffbf8addc06d41eb80a9bcab82d31fee290be4368339840e"

web3.sha3('getBalance(address) returns (uint256,string,bool,uint256,uint256,uint256)'); "0x02cd8e0e733ce057edefbb512190a6e6ecdae93ea96aa413d83cc7ad5c3d312c"

web3.sha3('getBalance(address) returns (uint256,string memory,bool,uint256,uint256,uint256)'); "0x48a0f2e06a2c0c3b033efbad3ecde8042792381edf9c600c2d1f7fb35a43c986"

web3.sha3('getBalance(address)'); "0xf8b2cb4f3943230388faeee074f1503714bff212640051caba01411868d14ae3"

Can someone please help.

  • The last one is correct: web3.sha3('getBalance(address)'). You'll want just the first four bytes (0xf8b2cb4f). If you're having trouble using that, please share the code / HTTP request you're making that uses that function selector. – user19510 May 6 at 16:33
  • @smarx That is not working for me. This is the request : {"jsonrpc":"2.0", "method":"eth_call", "params":[{"from": "eth.accounts[0]", "to": "0x9d13c6d3afe1721beef56b55d303b09e021e27ab", "data": "0xf8b2cb4f000000000000000000000000ed9d02e382b34818e88b88a309c7fe71e65f419d", "gas":4700000}],"latest", "id":1} – Tarun May 7 at 6:43
  • Response am getting is : <error> <code>-32602</code> <message>invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go struct field CallArgs.from of type common.Address</message> </error> If I use this from geth console, I get something which seems correct : var result = web3.eth.call({ to: "0x9d13c6d3afe1721beef56b55d303b09e021e27ab", data: "0xf8b2cb4f000000000000000000000000ed9d02e382b34818e88b88a309c7fe71e65f419d" }); – Tarun May 7 at 6:49
  • It looks like you're sending the quoted string "eth.accounts[0]" in the RPC request instead of the actual address. – user19510 May 7 at 9:46
  • @smarx yeah, you are right. that changed the error to : <message>invalid character 'e' looking for beginning of value</message> Seems now something wrong in data. – Tarun May 7 at 14:52
1

The return type of a function is not part of this signature.

See here for more details (specifically, take a look at the note).

If you want to encode your function, then you can try this (web3.js v1.x):

function encode(abiArray, functionName, functionArgs) {
    for (const object of abiArray)
        if (object.name == functionName)
            return web3.eth.abi.encodeFunctionCall(object, functionArgs);
    throw new Error("function " + functionName + " does not exist");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.