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. Create a crowdsale contract that can be used for the Initial Coin/Token Offering process. Import SafeMath for arithmetic operations:
pragma solidity ^0.4.23;import "./math/SafeMath.sol";contract CrowdSale {    // ..}
  1. If you are distributing tokens to investors, then import the token contract and create a state variable to keep the address of the distributable token contract:
pragma solidity ^0.4.23;import "./math/SafeMath.sol";import "./ERC20.sol";contract CrowdSale {    // The token sold through the ICO    ERC20 public token;}
  1. Tokens sold for each purchase are calculated at a rate; create a state variable to store it in the contract. The rate parameter stores the number of tokens the buyer gets for a Wei:
uint256 public rate; ...
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