Upgrading to Truffle 5 🍨

The bits we ❤️ and the bits we 😠 — overall a solid release with the great features.

Truffle 5 is a major overhaul and rework of the Truffle framework. There are several competing frameworks in the Ethereum space these days but Truffle is the market leader and most commonly used so it’s definitely worth keeping an 👀 on what’s going on over at Truffle HQ.

We have been using Truffle extensively for well over 18 months now, switching from a raw Web3JS library to a full build pipeline favouring features such as testing suite integration, CLI tools, multi-network support and deployment tools to name just a few.

We have had some small gripes with Truffle 4 but it has served us well over the last year but with the recent release of Truffle 5 the itch to upgrade was getting to us. We went for it and below are some of the best and worst bits which we found on the path to Truffle 5.

Web3JS 1.0 ✅

Truffle now come bundled with the latest Web3JS, this has a host of new additions but the one we love the most is the ability for us to use the PromiEvent construct when dealing with transactions, for example:

This is a much more fluent way of handling submission of transactions to the network. Previous all we had was a simple Promise which unfortunately doesn’t always fit when there are several states which a transaction can end up in. Previously, we used to use hacks like listening for events and timers checking every X seconds to work around this, the recent changes make it feel right.

Async/Await ✅

All Web3 calls are async/await — either when using them in tests, migrations or a webapp — this just makes life easier in most scenarios.

Additional Network Config ✅

Additional configuration options works well for us, we often price transactions at the lower end as we don’t always need them to go through immediately, with the new config we can increase the timeout and block confirmation, for example:

This means we can be more confident about running a migration and not worrying about it timing, which did happen with Truffle 4 migrations.

Revert Reason Strings ✅

A long overdue addition — bringing the latest changes to Solidity and Web3 to Truffle. Tests can now validate the failure reason and frontend logic can surface this reason if desired.

This has allowed us to tighten up our test and in one occasion find a false positive. Also surfacing some of these reasons to the frontend when needed is a big win for diagnosing potential issues.

BigNumber.js to BN.js 😠

The change to switch from BigNumber.js to BN.js took us by surprise. The majority of the time it took us to upgrade was going through the thousands of tests we have which utilised BigNumber and convert them to BN.js — I understand than the inclusion of web3 1.0 forced this move I just wished there was an easier way to do it. I have also found issues with using BN.js with bn-chai with should.js as detailed here.

Explicit conversion from ASCII to HEX 😠

This seems like an unnecessary change, presumably Truffle knows the method args and signature when making a call so I think the new requirement for explicitly converting to to HEX seems like a unneeded change, ideally it would the the type conversions for me in some way.

Function arguments of type bytes must now be converted to hexadecimal bytestrings using web3.utils.asciiToHex() .

Conclusion

To conclude the latest Truffle 5 release is a vast improvement and should be considered by all those running production ready Truffle deployments. All those involved should be proud of the many thousands of hours and commits which have gone into the release. Above are only some of the new features which we love and we are planning to explore and utilise many more of them in the future.

We will continue to use and support Truffle and see a very positive future in it. Full release notes can be found here https://github.com/trufflesuite/truffle/releases/tag/v5.0.0#user-content-what-s-new-in-truffle-v5-interacting-with-your-contracts-websockets

Peace out and a happy new year! blockrocket.tech

Follow us on twitter — @blockrockettech

Sign up to our community meetup — Blockchain Manchester