truffle-box / react-box

Truffle, Webpack and React boilerplate.
https://truffle-box.github.io/
MIT License
736 stars 251 forks source link

EthProvider for more than one contract? #183

Closed javierguzman closed 2 years ago

javierguzman commented 2 years ago

Hello all,

I have been learning about Truffle and I have realized that EthProvider.jsx seems to have be done only to work with one contract. What does it need to be change to allow more than one contract to be used? I guess state "data" would need to be an array instead of an object.

Would this be the only change? or is it not even needed and I am missing something? To be honest I was expecting the usage of multiple contracts out of the box.

Thank you in advance and regards

cliffoo commented 2 years ago

Great question @javierguzman ! Glad to hear you're learning about Truffle. The reason this box doesn't already support >1 contract is because it requires some way to generalize contracts (if you want it in an array like you suggested), which isn't difficult but adds complexity and clouds the intent of this box to be a simple boilerplate hooking up Truffle, web3js, and react.

You're on the right track. EthProvider, especially the init logic inside as well as the reducer state would need some change. The idea is to probe for multiple artifacts instead of just 1, and hold >1 contracts in state rather than just SimpleStorage.

In the meantime, look out for the nft rental marketplace tutorial (will probably release in early Oct.) The frontend part there will use this react box's client/, extending it to use different contracts. Stay tuned!

javierguzman commented 2 years ago

Thanks you @cliffoo for the quick response! I will be checking for the tutorial's releease in October. In the meantime then I will play around to see if I can manage to have this working with more than one contract. I close this but if I am successful I will come back to post my workaround.

Thank you again!