Skip to Content
Ethereum Cookbook
book

Ethereum Cookbook

by Manoj P R
August 2018
Intermediate to advanced
404 pages
11h 19m
English
Packt Publishing
Content preview from Ethereum Cookbook

There's more…

  1. You can have multiple bonus levels in your contract to provide a bonus based on different time durations, for example, 30% for the first day, 15% for the second day, and 5% for the third day.
  2. A struct can be used to save the bonus duration for each day:
// Custom data type to store bonus parameterstruct Bonus {    uint startTime;    uint endTime;    uint bonusPercent}// Array of fixed length to store 3 bonus levelsBonus[3] bonus;
  1. The values can be initialized through the constructor. Based on the bonus logic, you can either use an iteration or assign values individually. For simplicity, we are assigning each bonus duration individually:
constructor() {    bonus[0].startTime = openingTime;    bonus[0].endTime = openingTime + 1 days; bonus[0].bonusPercent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Ethereum Dapps

Building Ethereum Dapps

Roberto Infante
Ethereum For Dummies

Ethereum For Dummies

Michael G. Solomon

Publisher Resources

ISBN: 9781789133998Supplemental Content