Generate contract modules and function dynamically from the ABI
Hello everyone,
I've had an idea and I wanted to share it with you before working more on that to see if you like it or not.
Basically this module can generate Elixir modules from ABI specs. So you can use them closer to how you use them with web3.js
Example
iex> ExW3.DynamoContract.generate_module(ERC20, "priv/erc20.abi.json")
iex> ERC20.symbol |> ERC20.call(to: "0x6b1...71d0f")
{:ok, ["DAI"]}
The other benefit from this approach is it can also be done at compile time and have no runtime penalty.
Please let me know if you think this is a good approach so I can continue working on it.
Have a good one.
Freakin love it @alisinabh! Would definitely want it to be done at compile time.
Great to hear that @rupurt :smiley:
Then I have a few questions:
- Should I move this functionality into
ExW3.Contractmodule? - Are you OK with the current approach with call and send?
- Do we also need deployment functionality in case bytecode is available? If so do we want it in this PR or separately?
@alisinabh I think it would be best to do this in pieces.
For now I think this can be a different module than ExW3.Contract to do the contract generating at compile time. Maybe this will eventually replace ExW3.Contract.
We are okay with call and send, but open to different ideas.
The bytecode for deployment seems like a good separate step.
Hey,
Finally this is somewhat ready to review. Please check and let me know what should I change.
Cheers :beer:
@rupurt @hswick Do you have any ideas regarding the name of the module DynamoContract?
Hey @rupurt @hswick :wave:
Do you guys have time for a review?
@alisinabh I think this is looking pretty good. Only a few housekeeping comments.
Would you mind moving all the ERC20 contract stuff into test like the other examples? That way we don't need the priv dir, and the contracts module.
Last point is we need a section in the README that demonstrates a simple example, and maybe explains any details how to go about using DynamoContract in a project.
Also DynamoContract is goofy but its also awesome. At least it is unique. I've had a hard time coming up with a better name 😆 .
Thanks!
Hi @hswick,
Please check the new changes :)
Hey :wave: Just wanted to ping you guys the review. @hswick @rupurt
Hi Everyone,
I'm closing this PR in favour of my new library elixir_ethers which not only implements this but also adds some other functionality like documented generated functions and log filters.
If you need this please feel free to take a look and let me know of your thoughts.
Thanks