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...

For writing data to smart contracts, we have to follow this procedure:

  1. Consider the following example contract:
pragma solidity ^0.4.21;contract HelloWorld {    // State variable    string textToPrint = "hello world";    // State changing function    function changeText(string _text) public {        textToPrint = _text;    }    // Read-only function    function printSomething() public view returns (string) {        return textToPrint;    }}
  1. Create the contract instance with the ABI and the deployed address. The method to create an instance is slightly different between web3.js v0.2x.x and v1.x.x:
// For v0.2x.xvar helloWorld = web3.eth.contract(<ABI>);
var helloWorldInstance = helloWorld.at("<Address>");// For v1.x.xvar helloWorldInstance = new web3.eth.
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