Open hickscorp opened 5 years ago
I can look into this for next patch release.
In the meantime, the call method should be present on the object, even if not exposed through the TypeScript interface. Underlying it's a Tx object: https://github.com/xf00f/web3x/blob/master/web3x/src/contract/tx.ts#L68
So with appropriate casting you should be able to use it without tonnes of hackery.
@xf00f Thank you for the feedback.
contract.methods.doStuff(...)
gives me a TxSend<T>
. How would I cast that into a TxCall<T>
? The only way I found so far is:
// Inside a generic defining T from the original (method : TxSend<T>):
const callMethod : TxCall<T> = method as any;
Is this what you meant? I'm not sure - as if the underlying implementation changes, this would still compile and fail only at runtime...
Would it be a good idea to change the references to TxSend
in the web3x-codegen
project to either of:
Tx<${name}TransactionReceipt>
(https://github.com/xf00f/web3x/blob/v4.0.4/web3x/src/contract/tx.ts#L68)TxSendAndCall<${name}TransactionReceipt>
? TxSendWithLocalCallCheck<${name}TransactionReceipt>
? something else?) that inherits from TxSend
and TxCall
interfaces like the Tx
class, but includes some indication of the intended use (such as comments suggesting that developers use the TxCall
portions to check if the call would work locally, and then use the TxSend
portions to actually call the method). The references to TxSend
:
The fact that a
contract.methods.aTransactionMethod(args...).send()
is available but not acontract.methods.aTransactionMethod(args...).call()
is a big problem for us, as it is very common practice to run acall
"blank" before performing a realsend
transaction.The reason behind this sort of choice is that
revert
messages cannot be read when they occur on asend
- they can only be read when usingcall
using direct bytecode ABI encoding.An example of what this led us to do:
We have to call it like this:
This is really cumbersome - it would be great to have access to
call
even on transaction methods exactly like web3 and truffle do - allowing for shooting "blanks".Please expose the option to
call
methods of contracts that are transactions.