2

Does anybody knows how to write an API inside a Truffle application?

2

No, Truffle is not a framework for APIs.

It is a wrapper around a smart-contract which enables the methods defined in smart-contract and makes it available as javascript code.

But you can.

Since it is like a node app, you can use any node.js modules to make it work as an API endpoint using hapi, express etc.

  • I tried to add express to truffle but I couldn't, do you know any post or tutorial which can help me? – arodriguezdonaire May 23 '16 at 16:39
  • Try it the other way round i.e adding web3 and/or pudding to a conventional node project where express is included in the npm project file you will then be able to expose a contract as conventional api. – JackWinters May 23 '16 at 18:13
1

If you mean API's in the traditional sense then no. However Smart Contracts can be considered as services or APIs in themselves, and that's an increasingly common usage of it. Truffle/Mix/Embark are good frameworks for writing "API's" in that sense.

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.