sol-rs icon indicating copy to clipboard operation
sol-rs copied to clipboard

How could I get a function iterator of a contract which can be put in as a parameter in eve.call()

Open fCorleone opened this issue 7 years ago • 4 comments
trafficstars

I found that if I want to call a function of a contract , this line will be used:

eve.call(contract.functions().NAME_OF_YOUR_FUNCTIONS());

How could I get all of the functions' iterator of function list of a contract. Thanks a lot if you could do me a favor.

fCorleone avatar Oct 15 '18 05:10 fCorleone

@fCorleone we don't expose anything like that currently. Could you elaborate why it would be useful? IT's also more ethabi issue than sol-rs.

tomusdrw avatar Oct 15 '18 07:10 tomusdrw

Yes, for the reason that I want to write a program that could parse a contract and get the function name of the contract, and automatically call the functions. But I just don't know how to write evm.call() line. Because the parameter put into the call function should be like contract.function.name(), but I can just get a string to represent the name of the function. So I wonder if I could change the string to the correct type so that I can put it into the eve.call function

fCorleone avatar Oct 15 '18 07:10 fCorleone

The whole point of ethabi-derive is to provide type-safe wrapper for contracts, so you cannot dynamically call a function given it's function name as a string, cause you wouldn't know what types of parameters it's expecting or returns.

What you can do is use ethabi directly, like here: https://docs.rs/ethabi/6.0.1/ethabi/struct.Contract.html#method.function This is untyped API that gives you a builder that will produce data field of a transaction that you should send to interact with the contract. You will most likely need to contstruct ActionParams on your own (https://github.com/paritytech/sol-rs/blob/master/solaris/src/evm.rs#L260), and maybe even expose more "raw" function to perform a call than current EVM exposes.

tomusdrw avatar Oct 15 '18 07:10 tomusdrw

Thank you a lot about this, it's very useful to me.

fCorleone avatar Oct 15 '18 07:10 fCorleone