exw3 icon indicating copy to clipboard operation
exw3 copied to clipboard

Generate contract modules and function dynamically from the ABI

Open alisinabh opened this issue 4 years ago • 9 comments

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.

alisinabh avatar Nov 08 '21 21:11 alisinabh

Freakin love it @alisinabh! Would definitely want it to be done at compile time.

rupurt avatar Nov 08 '21 22:11 rupurt

Great to hear that @rupurt :smiley:

Then I have a few questions:

  • Should I move this functionality into ExW3.Contract module?
  • 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 avatar Nov 09 '21 19:11 alisinabh

@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.

hswick avatar Nov 10 '21 16:11 hswick

Hey,

Finally this is somewhat ready to review. Please check and let me know what should I change.

Cheers :beer:

alisinabh avatar Nov 22 '21 21:11 alisinabh

@rupurt @hswick Do you have any ideas regarding the name of the module DynamoContract?

alisinabh avatar Nov 26 '21 15:11 alisinabh

Hey @rupurt @hswick :wave:

Do you guys have time for a review?

alisinabh avatar Dec 06 '21 16:12 alisinabh

@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!

hswick avatar Dec 20 '21 20:12 hswick

Hi @hswick,

Please check the new changes :)

alisinabh avatar Jan 16 '22 12:01 alisinabh

Hey :wave: Just wanted to ping you guys the review. @hswick @rupurt

alisinabh avatar Feb 05 '22 18:02 alisinabh

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

alisinabh avatar Apr 17 '23 17:04 alisinabh