2

In web3.js version 0.x:

The web3 module automatically determines the use of call or sendTransaction based on the method type.

So for example, instead of doing:

myContractInstance.myMethod.call(...)

You can do:

myContractInstance.myMethod(...)

In web3.js version 1.0, this no longer seems possible.

For the example above, you need to do:

myContractInstance.methods.myMethod.call(...)

So every function call becomes "lengthier", and in addition, the code which I have already written is not easily portable.


Is there any available wrapper for web3.js version 1.0, which allows using the same syntax as in web3.js version 0.x?

The relevant documentation for web3 v0.x is here.

The relevant documentation for web3 v1.0 is here.

Thank you!

0

As a workaround, you can automate the generating of the syntax in general by parsing the ABI, it holds all information about the function (name, modifier, inputs and outputs) necessary to generate the syntax needed. I did that for truffle and can really recommend doing so as it prevents you from doing mistakes when writing the commands manually.

  • Thanks, thought about this. It would be way "lengthier" than the current solution though. – goodvibration Jun 18 '18 at 9:39
  • What do you mean "for Truffle"? Truffle already uses web3.js v0.x. – goodvibration Jun 18 '18 at 9:40
  • It's a one time effort that's really worth it. It's a script that generates truffle syntax code to interact with the contract. – Nikita Fuchs Jun 18 '18 at 9:42

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.