1

UPDATED: Sorry for Inconvenience, I have updated all my question and accept my apology , being naive user.

I have encoded getter functions of my contract i.e. 0x27e235e30000000000000000000000000000000000000000000000000000000000000000................ In this encoded function, there may be one, two or three arguments lets say address, string, uint. Such function may return one/two values i.e. uint/string. Now I want to call that encoded function and get its return values. which then i print them on console and also save into my array. I am trying following code, which is printing receipt of my transaction, as expected. But I want to print/save return values (returned by contract function).

try {
        await web3.eth.sendTransaction(
        {from:account1,
        to:myContAddr,
        data: myFunc
            }).then(function(res){
              console.log("Normal Getter", res);
              myResult.push(res);
          });
    } catch (error) {
      console.log(" Normal Getters: ERROR !"); 
    }

Should I have to decode such encoded function to extract arguments and methodID separately, and then call it ???

Note: A list of such encoded function is provided to me and also i have ABIs.

3
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat.
    – eth
    Commented Dec 17, 2019 at 7:07
  • The return value can be obtained for view functions if you use call ethereum.stackexchange.com/questions/765/…. For regular transactions it cannot be obtained easily and you have to trace them, the recommended alternative is to use events instead of return for transactions.
    – Ismael
    Commented Dec 17, 2019 at 20:35
  • but i have encoded all values ... functionname and its parameters are encoded ... , please read my question againg...
    – Amir Ali
    Commented Dec 18, 2019 at 0:58

1 Answer 1

0

Try this:

const ABI =
[
    {
        constant: true,
        inputs: [ { name: 'caller', type: 'address' } ],
        name: 'getTotalSupply',
        outputs: [ { name: '', type: 'uint256' } ],
        payable: false,
        stateMutability: 'view',
        type: 'function'
    }
];

async function getTotalSupply(myContAddr, callerAddr) {
    const contract = new web3.eth.Contract(ABI, myContAddr);
    return await contract.methods.getTotalSupply(callerAddr).call();
}
3
  • 1
    thanks for your efforts.. BUT.. i have this encoded getter function. Let me explain. I have ABI from where i can extract ALL thing about my function/contract, except the VALUES for my function parameters. For example, my function take three arguemnts (1. address, 2. string, and 3.uint256), then how could i call that function with some arguments. Therefore, for arguments values i must have to consult the provided list of encoded function (with arguments values)... So, in this case your answer is not applicable..
    – Amir Ali
    Commented Dec 16, 2019 at 11:23
  • 1
    @AmirAli: That's NOT what your question says! Commented Dec 16, 2019 at 11:44
  • 1
    I have made another update.. now
    – Amir Ali
    Commented Dec 16, 2019 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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