Book Image

Truffle Quick Start Guide

By : Nikhil Bhaskar
Book Image

Truffle Quick Start Guide

By: Nikhil Bhaskar

Overview of this book

Truffle is a world-class development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier. If you are a web developer wanting to try your hand at developing Dapps with Truffle, then this is the book for you. This book will teach you to write smart contracts and build Dapps with Truffle. You will begin with covering the basics of Truffle, briefly explaining how it integrates Solidity and Web3, in orderto start building a mini decentralized application. Also, you will dive into migration, testing and integrating Truffle with the use of popular JavaScript frameworks. Lastly, you will ship your decentralized application and package it into a product. Moreover, you will go through the best practices in Truffle,so as to increase your proficiency in building Dapps with Truffle. By the end of the book, you will be able to write smart contracts and build decentralized applications with Truffle on Ethereum blockchains.
Table of Contents (9 chapters)

Testing for Solidity events

We briefly touched on testing for events but we did not get into much detail. Now is the time.

Events are a great way to let the client (frontend) know what has happened, and they're great for providing metadata about a transaction or public function invocation of your Solidity smart contract. Along with testing the state modifications of a transaction, return value of a view function, and modifiers, we can also test whether an event was emitted with the appropriate metadata.

Right now, our TaskMaster contract has no events. Let's quickly add one.

Inside the TaskMaster.sol file, underneath the state variable declarations and before the constructor, add the following line of code:

event LogRecipientRewarded(address recipient, uint rewardAmount);

This is how you declare an event in Solidity.

We call it LogRecipientRewarded. We also specify the...