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.

Amir Ali
  • 447
  • 6
  • 18
  • 1
    Comments are not for extended discussion; this conversation has been moved to chat. – eth Dec 17 '19 at 07:07
  • The return value can be obtained for view functions if you use call https://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call. 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 Dec 17 '19 at 20:35
  • but i have encoded all values ... functionname and its parameters are encoded ... , please read my question againg... – Amir Ali Dec 18 '19 at 00:58

1 Answers1

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();
}
goodvibration
  • 26,003
  • 5
  • 46
  • 86
  • 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 Dec 16 '19 at 11:23
  • 1
    @AmirAli: That's NOT what your question says! – goodvibration Dec 16 '19 at 11:44
  • 1
    I have made another update.. now – Amir Ali Dec 16 '19 at 12:00