Closed saarshah closed 4 years ago
Hi @saarshah, unfortunately this is not a support forum so in the future the best place to ask and have your questions answered would be: https://ethereum.stackexchange.com
In my experience the easiest way to call the getter function you are looking for would be to instantiate the contract with web3.js using the jsonInterface
and address
:
const contract = new web3.eth.Contract(jsonInterface[, address][, options])
The const contract
should then have your contract methods
on it, including getters if you set up your contract code correctly, which you can then call using methods.myMethod.call.
Thanks for your answer... I already asked there, but no one is replying... I think, you did't got my point... I am asking help for my scenario, not for available easiest options.... i know them all. My scenario is to call contract function (which is in encoded form with all its parameters), can you please reconsider my question ? May be my question is demanding new feature, since I think, to call contract function with encoded values , such feature is not available in web3js, so far..v(if i am not wrong. ??????
@saarshah I understand your frustration, but I think @ryanio was right on closing this issue. Your question is not related to this library.
What you are looking for is probably eth_call
. You should call it manually through your web3 provider, using the encoded sig+params as data
.
I have encoded function of my smart contract, which has methodID and parameters i.e. 0xf7ea7a3d4000000000000000000015000000000000000000ff7f0000b200000000f7ea7a............... Suppose, in this encoded function, there are also two arguments , one is uint and other is string. This encoded function actually is a getter (not changing status) of my contract (means in ABI its stateMutability =view) and also it return a value i.e. totalSupply. Now, i want to call this funciton through web3js/nodejs, as below. This code gives me transaction receipt/hash, as expected, but i am interested to retrieve the getter function return value i.e. totalSupply;
One possible solution is to extract function Signature/methodID (which is easy for me) from given encoded function and its parameters (yet, not known to me how to decode parameters) and call function like this .. i.e.
So, my questions are