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

How to do it…

  1. Inherit the winnable DAL contract created in the previous recipe. Since the investments are usually handled using an ERC20 token, import the StandardToken contract from the openzeppelin library:
pragma solidity^0.4.23;import "./WinnableDAL.sol";import "./StandardToken.sol";contract InvestableDAL is WinnableDAL, StandardToken {    //...}
  1. Create an invest function, which accepts investments from the user and allocates tokens accordingly:
function invest() public {    //...}
  1. For simplicity, assume that each investor gets one token per Ether invested. Use the standard token functions to mint and allocate tokens:
address investor = msg.sender;uint tokens = msg.value;mint(investor, tokens);
  1. Create a state variable to store the dividend ...
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