7

maybe this is a very simple question but I've tried unsuccesfully to understand the difference between truffle-contract and web3.eth.Contract from web3.js 1.0.

As far as I've understood they seems to me two different module used for working with smart contracts' abstraction.

Am I missing something? If they both serve the same purpose which one should I use (functionalities, easy-to-use,ecc)?

Thanks.

  • 2
    Truffle-contract was based on web3 v0.20 but with promises instead of callbacks. Now web3 v1.0 has "promievents" so functionality is similar but syntaxis is different. Web3 v1.0 is still beta and Truffle is working in separate branches versions compatible with web3 v1.0. – Ismael May 1 '18 at 18:57
  • Why is truffle-contract still necessary for web3 1.0.0? At least in my case, it only created confusion. – Paul Berg Nov 23 '18 at 19:13
5

As pointed out by @Ismael in the comment and after some days spent working with both library I can confirm what he has written.

Truffle-contract is based on the stable version of web3 (v0.20), so it use promises and allow you to perform contract operation and methods in Javascript.

Web3 v1.0.0 (which is still in beta) use Promise and Promievents, so web3.eth.Contract allows you to interact with your contract like truffle-conctract but it has in my opinion more funcionalities.

One thing to note is that the utility of truffle test docs and docs gives you an istance of web3 and truffle-contract so (if I'm not wrong) you can't for now use web3.eth.Contract in .js truffle test.

-2

Truffle is a development environment. Even if you developed your smart contract in truffle, you are required to use web3 to interact with your contract from a browser. It is not a so valid comparison IMO. I would recommend using Truffle, if you are familiar with node.js. Otherwise, it would be better to go on with remix Online IDE to develop and test your smart contracts.

  • In my question I refer to truffle-contract, the module developed by the truffle suite used to interact with contract in JavaScript, not Truffle the framework. – Luigi Cerone May 1 '18 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.