Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS

Mark Smalley
Mark SmalleyCo-Founder and CEO at Neuroware
BLOCKCHAIN DEVELOPERS MALAYSIA
http://neuroware.io
Meetup #4 - Back to Tech - March, 2018
sponsored by
BLOCKCHAIN DEVELOPER PRESENTATIONS & LIVE DEMOS
MARK SMALLEY ( Neuroware.io ) - CRUDy Ethereum Contracts
TM LEE ( CoinGecko.com ) - Crypto Wallet Walkthroughs
ADAM MASHRIQUE ( LuxTag.io ) - Lightning Networks via Vue.js
CRUDy Ethereum Contracts
PART 1 - CREATE, READ, UPDATE & DELETE DATA
INTRODUCING THE BIG BLOCK BITCOIN MINIMALIST
Mark Smalley - CEO ( Neuroware.io )
Living in Malaysia for the past 20 Years
Building FinTech Applications for 15 Years
Spent 10 Years Helping Tech Communities
Building Blockchain Apps for 5 Years
INTRODUCING R1 DOT MY SDN BHD
GLOBAL
FUNDING
Only Malaysian company to graduate
from 500 Startups Accelerator in Silicon
Valley, with funding from Coinsilium too
FINTECH
FOCUS
With DBS, Maybank and Securities
Commission of Malaysia as clients, we
have a broad understanding of fintech
FULL-STACK
SERVICES
We provide corporate blockchain
training and workshops along with
consulting on solutions utilizing Cortex
NEUROWARE
enterprise infrastructure
BCE.ASIA
consortium
BLOCKSTRAP
framework
ENOUGH ABOUT ME
LET’S RECAP LAST MONTH’S TOPIC
TOKENIZING ASSETS WITH BLOCKCHAINS
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS
Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS
ENOUGH ABOUT THE BLOCKCHAIN EMBASSY OF ASIA (www.BCE.asia)
WHY ARE WE TALKING ABOUT CRUDY CONTRACTS …?
IMMUTABLE CODE IS VERY DIFFERENT TO IMMUTABLE DATA
MOVING BEYOND TOKEN GENERATION
CREATE READ UPDATE DESTROY
ETHEREUM’S BIGGEST SURPRISES
● An object oriented language without objects
● A static typing language with only one type
● Indexes via mapped hash tables cannot be removed
● Indexes cannot be natively counted
● Moving beyond 32 byte dynamic chunks is complicated
● Output functionality is even more restrictive than inputs
ONE TYPE TO RULE THEM ALL
Inline data types available within contracts includes:
● Booleans
● Integers
● Addresses
● Strings
● Bytes
Data types stored on the blockchain:
● Byte arrays
DEFINING VARIABLE TYPES AND THEIR VISIBILITY
contract CRM
{
bool internal deactivated = 0;
uint public contact_count = 0;
address private contract_owner;
string external owner_name = “Mark”;
function CRM(string name)
{
contract_owner = msg.sender;
owner_name = name;
}
}
Global variables automatically available
anywhere within the contract include:
● block (current height, gas, difficulty, etc)
● msg (data, gas, sender, value, etc)
● now (alias for block.timestamp)
● tx (gas price & origin)
function is auto initiated if its
the same as contract name
ONE DIMENSIONAL ARRAYS
● All four data types (other than strings) can be set as arrays
● Arrays can only contain the same data type
● Constructing arrays within functions requires length definitions
● Don’t forget that strings are also arrays (chunks are relative)
● Arrays used for input & output parameters cannot be strings
USING ARRAYS
contract CRM
{
uint[] private owner_ip_address;
address[] public owners;
function SwitchOwner(string ip_address, address new_owner)
{
if(msg.sender == contract_owner)
{
contract_owner = new_owner;
owners.push(contract_owner);
owner_ip_address = string_to_array(ip_address, “.”);
}
}
}
BUILDING NEW ARRAYS
uint[] private owner_ip4_address;
address[] public owners;
uint[] public owner_switch_blocks;
function SwitchOwner(string ip_address, address new_owner)
returns(uint[] previous_owner)
{
uint[] memory previous = new uint[](6);
if(msg.sender == contract_owner)
{
contract_owner = new_owner;
owners.push(contract_owner);
owner_switch_blocks.push(block.number);
owner_ip_address = string_to_array (ip_address, “.”);
previous[0 to 3] = owner_ip_address[0 to 3];
previous[4] = owner_switch_blocks[owner_switch_blocks.length - 1];
previous[5] = owner_switch_blocks.length;
}
return previous; // Everything but the name :-(
}
STRUCTS TO THE RESCUE !!! ???
contract CRM
{
struct owner
{
address id;
string name;
uint[] ip;
}
owner[] public owners; // manual auto inc id ???
function CRM(string owner_name, uint[] ip_address)
{
owner new_owner;
new_owners.id = msg.sender;
new_owners.name = owner_name;
new_owners.ip = ip_address;
owners.push(new_owner);
}
}
INDEXING VIA HASH TABLES - ALREADY REMOVES 4 LINES
contract CRM
{
struct owner
{
string name;
uint[] ip;
}
mapping(address => owner) owners;
function CRM(string owner_name, uint[] ip_address)
{
// can then create, read & update with key ...
owners[msg.sender].name = owner_name;
owners[msg.sender].ip = ip_address;
}
}
HOWEVER
● Structs cannot be returned
● Struct parameters cannot be counted natively
● Mappings cannot be counted
-- which requires index counts to be managed separately
● Mappings cannot be removed
● Mappings cannot be collectively returned
-- returned results must also be singular types of arrays
IN ALL HONESTY - IT’S BYTES THAT SAVE THE DAY !!!
struct owner
{
string name;
uint[] ip;
}
mapping(address => owner) owners;
uint owner_count = 0;
function CRM(string owner_name, uint[] ip_address)
returns(bytes32[] owner)
{
bytes32[] memory new_owner = new bytes32[](2);
new_owner[0] = string_to_bytes (owner_name);
new_owner[1] = combine(ip_address[0 to 4])
owners[msg.sender].name = owner_name;
owners[msg.sender].ip = ip_address;
owner_count++; // manual owner count management
return new_owner
}
THE ONLY WAY TO DELETE - STEP 1 - BE PREPARED ???
struct owner
{
bool is_active;
string name;
uint[] ip;
}
mapping(address => owner) owners;
uint owner_count = 0;
function CRM(string owner_name, uint[] ip_address)
{
bytes32[] memory new_owner = new bytes32[](2);
owners[msg.sender].is_active = 1; // activate
owners[msg.sender].name = owner_name;
owners[msg.sender].ip = ip_address;
owner_count++; // manual owner count management
}
THE ONLY WAY TO DELETE - STEP 2 - COST EFFECTIVE UPDATING
struct owner
{
bool is_active;
string name;
uint[] ip;
}
mapping(address => owner) owners;
uint owner_count = 0;
function destroy(address owner_id)
{
owners[owner_id].is_active = 0; // this costs ether
owner_count--; // manual owner count management
}
WRITING DATA COSTS MONEY
CRUDy RECAP - CREATE NEW RECORD
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function create(
address user_address,
string user_name,
string user_email
) onlyOwner public {
users[user_address].is_active = 1;
users[user_address].name = user_name;
users[user_address].email = user_email;
}
}
CRUDy RECAP - READ RECORD
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function read(address user_address) public
returns(string user_name, string user_email)
{
return(
users[user_address].name,
users[user_address].email
)
}
}
CRUDy RECAP - UPDATE RECORDED DATA BY INDEX
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function update(
address user_address,
string user_name,
string user_email
) onlyOwner public {
require(users[user_address].is_active == 1);
users[user_address].name = user_name;
users[user_address].email = user_email;
}
}
CRUDy RECAP - UPDATE INDEX
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function update_index(
address old_address,
string new_address
) onlyOwner public {
require(users[old_address].is_active == 1);
users[new_address].name = users[old_address].name;
users[new_address].email = users[old_address].email;
users[new_address].is_active = 1;
users[old_address].is_active = 0;
}
}
CRUDy RECAP - DESTROY RECORDS
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
function destroy(address user_address) onlyOwner public
{
require(users[user_address].is_active == 1);
users[user_address].is_active = 0;
}
}
CRUDy RECAP - COMPLICATED BY COUNTS
contract CRM
{
struct user
{
string name;
string email;
bool is_active;
}
mapping(address => user) users;
uint public user_count;
function destroy(address user_address) onlyOwner public
{
require(users[user_address].is_active == 1);
users[user_address].is_active = 0;
user_count--;
}
}
CRUDy RECAP - EVEN MORE SO WITH JOINS
struct user
{
string name;
string email;
bool is_active;
uint index_key;
}
mapping(address => user) users;
address[] public user_indexes;
function destroy(address user_address) onlyOwner public
{
require(users[user_address].is_active == 1);
users[user_address].is_active = 0;
users[user_indexes[user_indexes.length - 1]].index_key =
users[user_address].index_key
user_indexes[users[user_address].index_key] =
user_indexes[user_indexes.length - 1];
user_indexes.length = user_index.length - 1;
}
CAVEATS - WORKING WITH STRINGS
● Since strings cannot be returned from external contracts every
contract dealing with strings needs it own conversion functions
● Converting strings to 32 byte arrays allow anything to be
returned - so long as each value is within 32 bytes, which
also requires the decoding to be done by the client
● Which brings us to what I thought we would cover today ...
WHAT ABOUT CRUD BEYOND PREDEFINED STRUCTURE ???
CREATE READ UPDATE DESTROY
TO BE CONTINUED IN PART 2
CREATING A DATABASE WITHIN A CONTRACT
email the team anytime - founders@neuroware.io
1 of 35

Recommended

Cs1123 12 structures by
Cs1123 12 structuresCs1123 12 structures
Cs1123 12 structuresTAlha MAlik
578 views30 slides
Java beginners meetup: Introduction to class and application design by
Java beginners meetup: Introduction to class and application designJava beginners meetup: Introduction to class and application design
Java beginners meetup: Introduction to class and application designPatrick Kostjens
109 views32 slides
React in 45 Minutes (Jfokus) by
React in 45 Minutes (Jfokus)React in 45 Minutes (Jfokus)
React in 45 Minutes (Jfokus)Maarten Mulders
213 views52 slides
Java căn bản - Chapter4 by
Java căn bản - Chapter4Java căn bản - Chapter4
Java căn bản - Chapter4Vince Vo
435 views49 slides
MongoDB Days Silicon Valley: Building an Artificial Intelligence Startup with... by
MongoDB Days Silicon Valley: Building an Artificial Intelligence Startup with...MongoDB Days Silicon Valley: Building an Artificial Intelligence Startup with...
MongoDB Days Silicon Valley: Building an Artificial Intelligence Startup with...MongoDB
1.2K views23 slides
Building an An AI Startup with MongoDB at x.ai by
Building an An AI Startup with MongoDB at x.aiBuilding an An AI Startup with MongoDB at x.ai
Building an An AI Startup with MongoDB at x.aiMongoDB
5.1K views23 slides

More Related Content

Similar to Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS

Benefits of Using MongoDB Over RDBMSs by
Benefits of Using MongoDB Over RDBMSsBenefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSsMongoDB
7.2K views63 slides
Building Services With gRPC, Docker and Go by
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and GoMartin Kess
1.4K views61 slides
C++ tutorials by
C++ tutorialsC++ tutorials
C++ tutorialsDivyanshu Dubey
563 views79 slides
Lab 13 by
Lab 13Lab 13
Lab 13Adnan Raza
251 views11 slides
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze by
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices CrazeKnots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices CrazeAlexander Shopov
434 views39 slides

Similar to Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS(20)

Benefits of Using MongoDB Over RDBMSs by MongoDB
Benefits of Using MongoDB Over RDBMSsBenefits of Using MongoDB Over RDBMSs
Benefits of Using MongoDB Over RDBMSs
MongoDB7.2K views
Building Services With gRPC, Docker and Go by Martin Kess
Building Services With gRPC, Docker and GoBuilding Services With gRPC, Docker and Go
Building Services With gRPC, Docker and Go
Martin Kess1.4K views
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze by Alexander Shopov
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices CrazeKnots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
Knots - the Lazy Data Transfer Objects for Dealing with the Microservices Craze
Alexander Shopov434 views
Chapter 4 - Defining Your Own Classes - Part I by Eduardo Bergavera
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
Eduardo Bergavera1.7K views
DDD - 2 - Domain Driven Design: Tactical design.pdf by Eleonora Ciceri
DDD - 2 - Domain Driven Design: Tactical design.pdfDDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdf
Eleonora Ciceri812 views
CHAPTER -4-class and structure.pptx by GebruGetachew2
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
GebruGetachew213 views
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ... by MongoDB
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB1.5K views
C# Advanced L02-Operator Overloading+Indexers+UD Conversion by Mohammad Shaker
C# Advanced L02-Operator Overloading+Indexers+UD ConversionC# Advanced L02-Operator Overloading+Indexers+UD Conversion
C# Advanced L02-Operator Overloading+Indexers+UD Conversion
Mohammad Shaker782 views
A Note On Computer Statement by Krista Clark
A Note On Computer StatementA Note On Computer Statement
A Note On Computer Statement
Krista Clark2 views
Writing MySQL UDFs by Roland Bouman
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
Roland Bouman10.8K views
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019 by Victor Rentea
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Victor Rentea1.6K views
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC by Clément OUDOT
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSCRMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
Clément OUDOT2.9K views
Get together on getting more out of typescript & angular 2 by Ruben Haeck
Get together on getting more out of typescript & angular 2Get together on getting more out of typescript & angular 2
Get together on getting more out of typescript & angular 2
Ruben Haeck185 views

More from Mark Smalley

An Introduction to Upgradable Smart Contracts by
An Introduction to Upgradable Smart ContractsAn Introduction to Upgradable Smart Contracts
An Introduction to Upgradable Smart ContractsMark Smalley
518 views30 slides
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress by
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPressBDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPressMark Smalley
472 views30 slides
BDM Meetup #1 - Blockchains for Developers - Part 01 by
BDM Meetup #1 - Blockchains for Developers - Part 01BDM Meetup #1 - Blockchains for Developers - Part 01
BDM Meetup #1 - Blockchains for Developers - Part 01Mark Smalley
798 views43 slides
Neuroware.io at FINNOVASIA KL - 2016 by
Neuroware.io at FINNOVASIA KL - 2016Neuroware.io at FINNOVASIA KL - 2016
Neuroware.io at FINNOVASIA KL - 2016Mark Smalley
954 views40 slides
Banking on The Future of Blockchains by
Banking on The Future of BlockchainsBanking on The Future of Blockchains
Banking on The Future of BlockchainsMark Smalley
2.7K views80 slides
LVLUPKL - My Life on The Blockchain by
LVLUPKL - My Life on The BlockchainLVLUPKL - My Life on The Blockchain
LVLUPKL - My Life on The BlockchainMark Smalley
1.1K views33 slides

More from Mark Smalley(19)

An Introduction to Upgradable Smart Contracts by Mark Smalley
An Introduction to Upgradable Smart ContractsAn Introduction to Upgradable Smart Contracts
An Introduction to Upgradable Smart Contracts
Mark Smalley518 views
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress by Mark Smalley
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPressBDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
BDM Meetup 2 - Blockchain Basics - Generating Keys for BloqPress
Mark Smalley472 views
BDM Meetup #1 - Blockchains for Developers - Part 01 by Mark Smalley
BDM Meetup #1 - Blockchains for Developers - Part 01BDM Meetup #1 - Blockchains for Developers - Part 01
BDM Meetup #1 - Blockchains for Developers - Part 01
Mark Smalley798 views
Neuroware.io at FINNOVASIA KL - 2016 by Mark Smalley
Neuroware.io at FINNOVASIA KL - 2016Neuroware.io at FINNOVASIA KL - 2016
Neuroware.io at FINNOVASIA KL - 2016
Mark Smalley954 views
Banking on The Future of Blockchains by Mark Smalley
Banking on The Future of BlockchainsBanking on The Future of Blockchains
Banking on The Future of Blockchains
Mark Smalley2.7K views
LVLUPKL - My Life on The Blockchain by Mark Smalley
LVLUPKL - My Life on The BlockchainLVLUPKL - My Life on The Blockchain
LVLUPKL - My Life on The Blockchain
Mark Smalley1.1K views
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications by Mark Smalley
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain ApplicationsBlockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications
Blockstrap at FOSS Asia - 2015 - Building Browser-Based Blockchain Applications
Mark Smalley1.1K views
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014 by Mark Smalley
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014
Bitcoin is Still Technology - Presented at Bitcoin World Conference KL - 2014
Mark Smalley2.4K views
Logging-In with Bitcoin - Paywalls without Emails by Mark Smalley
Logging-In with Bitcoin - Paywalls without EmailsLogging-In with Bitcoin - Paywalls without Emails
Logging-In with Bitcoin - Paywalls without Emails
Mark Smalley3.4K views
Programmable Money - Visual Guide to Bitcoin as a Technology by Mark Smalley
Programmable Money - Visual Guide to Bitcoin as a TechnologyProgrammable Money - Visual Guide to Bitcoin as a Technology
Programmable Money - Visual Guide to Bitcoin as a Technology
Mark Smalley11.8K views
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies by Mark Smalley
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic CurrenciesIntroducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies
Introducing Bitcoin :: The (Mostly) Visual-Guide to Cryptographic Currencies
Mark Smalley31.5K views
1st NoSQL Asia Event in Malaysia by Mark Smalley
1st NoSQL Asia Event in Malaysia1st NoSQL Asia Event in Malaysia
1st NoSQL Asia Event in Malaysia
Mark Smalley977 views
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia by Mark Smalley
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in MalaysiaMongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia
MongoDB Day KL - 2013 :: Keynote - The State of MongoDB in Malaysia
Mark Smalley499 views
JSON, The Argonauts and Mark by Mark Smalley
JSON, The Argonauts and MarkJSON, The Argonauts and Mark
JSON, The Argonauts and Mark
Mark Smalley1.6K views
JSON and The Argonauts by Mark Smalley
JSON and The ArgonautsJSON and The Argonauts
JSON and The Argonauts
Mark Smalley1.2K views
Serving Images with GridFS by Mark Smalley
Serving Images with GridFSServing Images with GridFS
Serving Images with GridFS
Mark Smalley4.8K views
Why I Believe MongoDB is The Dog's Bollocks by Mark Smalley
Why I Believe MongoDB is The Dog's BollocksWhy I Believe MongoDB is The Dog's Bollocks
Why I Believe MongoDB is The Dog's Bollocks
Mark Smalley2.1K views
Introducing MongoPress by Mark Smalley
Introducing MongoPressIntroducing MongoPress
Introducing MongoPress
Mark Smalley2.8K views

Recently uploaded

Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...NUS-ISS
16 views28 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
50 views21 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
27 views43 slides
SAP Automation Using Bar Code and FIORI.pdf by
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdfVirendra Rai, PMP
19 views38 slides
PharoJS - Zürich Smalltalk Group Meetup November 2023 by
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023Noury Bouraqadi
120 views17 slides
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
16 views6 slides

Recently uploaded(20)

Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex19 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... by NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS28 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS27 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
[2023] Putting the R! in R&D.pdf by Eleanor McHugh
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh38 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views

Blockchain Developers Malaysia Meetup #4 - CRUDy Ethereum Contracts, Wallet Walkthrough and Lightning via VueJS

  • 1. BLOCKCHAIN DEVELOPERS MALAYSIA http://neuroware.io Meetup #4 - Back to Tech - March, 2018 sponsored by BLOCKCHAIN DEVELOPER PRESENTATIONS & LIVE DEMOS MARK SMALLEY ( Neuroware.io ) - CRUDy Ethereum Contracts TM LEE ( CoinGecko.com ) - Crypto Wallet Walkthroughs ADAM MASHRIQUE ( LuxTag.io ) - Lightning Networks via Vue.js
  • 2. CRUDy Ethereum Contracts PART 1 - CREATE, READ, UPDATE & DELETE DATA
  • 3. INTRODUCING THE BIG BLOCK BITCOIN MINIMALIST Mark Smalley - CEO ( Neuroware.io ) Living in Malaysia for the past 20 Years Building FinTech Applications for 15 Years Spent 10 Years Helping Tech Communities Building Blockchain Apps for 5 Years
  • 4. INTRODUCING R1 DOT MY SDN BHD GLOBAL FUNDING Only Malaysian company to graduate from 500 Startups Accelerator in Silicon Valley, with funding from Coinsilium too FINTECH FOCUS With DBS, Maybank and Securities Commission of Malaysia as clients, we have a broad understanding of fintech FULL-STACK SERVICES We provide corporate blockchain training and workshops along with consulting on solutions utilizing Cortex NEUROWARE enterprise infrastructure BCE.ASIA consortium BLOCKSTRAP framework
  • 5. ENOUGH ABOUT ME LET’S RECAP LAST MONTH’S TOPIC TOKENIZING ASSETS WITH BLOCKCHAINS
  • 9. ENOUGH ABOUT THE BLOCKCHAIN EMBASSY OF ASIA (www.BCE.asia) WHY ARE WE TALKING ABOUT CRUDY CONTRACTS …?
  • 10. IMMUTABLE CODE IS VERY DIFFERENT TO IMMUTABLE DATA
  • 11. MOVING BEYOND TOKEN GENERATION CREATE READ UPDATE DESTROY
  • 12. ETHEREUM’S BIGGEST SURPRISES ● An object oriented language without objects ● A static typing language with only one type ● Indexes via mapped hash tables cannot be removed ● Indexes cannot be natively counted ● Moving beyond 32 byte dynamic chunks is complicated ● Output functionality is even more restrictive than inputs
  • 13. ONE TYPE TO RULE THEM ALL Inline data types available within contracts includes: ● Booleans ● Integers ● Addresses ● Strings ● Bytes Data types stored on the blockchain: ● Byte arrays
  • 14. DEFINING VARIABLE TYPES AND THEIR VISIBILITY contract CRM { bool internal deactivated = 0; uint public contact_count = 0; address private contract_owner; string external owner_name = “Mark”; function CRM(string name) { contract_owner = msg.sender; owner_name = name; } } Global variables automatically available anywhere within the contract include: ● block (current height, gas, difficulty, etc) ● msg (data, gas, sender, value, etc) ● now (alias for block.timestamp) ● tx (gas price & origin) function is auto initiated if its the same as contract name
  • 15. ONE DIMENSIONAL ARRAYS ● All four data types (other than strings) can be set as arrays ● Arrays can only contain the same data type ● Constructing arrays within functions requires length definitions ● Don’t forget that strings are also arrays (chunks are relative) ● Arrays used for input & output parameters cannot be strings
  • 16. USING ARRAYS contract CRM { uint[] private owner_ip_address; address[] public owners; function SwitchOwner(string ip_address, address new_owner) { if(msg.sender == contract_owner) { contract_owner = new_owner; owners.push(contract_owner); owner_ip_address = string_to_array(ip_address, “.”); } } }
  • 17. BUILDING NEW ARRAYS uint[] private owner_ip4_address; address[] public owners; uint[] public owner_switch_blocks; function SwitchOwner(string ip_address, address new_owner) returns(uint[] previous_owner) { uint[] memory previous = new uint[](6); if(msg.sender == contract_owner) { contract_owner = new_owner; owners.push(contract_owner); owner_switch_blocks.push(block.number); owner_ip_address = string_to_array (ip_address, “.”); previous[0 to 3] = owner_ip_address[0 to 3]; previous[4] = owner_switch_blocks[owner_switch_blocks.length - 1]; previous[5] = owner_switch_blocks.length; } return previous; // Everything but the name :-( }
  • 18. STRUCTS TO THE RESCUE !!! ??? contract CRM { struct owner { address id; string name; uint[] ip; } owner[] public owners; // manual auto inc id ??? function CRM(string owner_name, uint[] ip_address) { owner new_owner; new_owners.id = msg.sender; new_owners.name = owner_name; new_owners.ip = ip_address; owners.push(new_owner); } }
  • 19. INDEXING VIA HASH TABLES - ALREADY REMOVES 4 LINES contract CRM { struct owner { string name; uint[] ip; } mapping(address => owner) owners; function CRM(string owner_name, uint[] ip_address) { // can then create, read & update with key ... owners[msg.sender].name = owner_name; owners[msg.sender].ip = ip_address; } }
  • 20. HOWEVER ● Structs cannot be returned ● Struct parameters cannot be counted natively ● Mappings cannot be counted -- which requires index counts to be managed separately ● Mappings cannot be removed ● Mappings cannot be collectively returned -- returned results must also be singular types of arrays
  • 21. IN ALL HONESTY - IT’S BYTES THAT SAVE THE DAY !!! struct owner { string name; uint[] ip; } mapping(address => owner) owners; uint owner_count = 0; function CRM(string owner_name, uint[] ip_address) returns(bytes32[] owner) { bytes32[] memory new_owner = new bytes32[](2); new_owner[0] = string_to_bytes (owner_name); new_owner[1] = combine(ip_address[0 to 4]) owners[msg.sender].name = owner_name; owners[msg.sender].ip = ip_address; owner_count++; // manual owner count management return new_owner }
  • 22. THE ONLY WAY TO DELETE - STEP 1 - BE PREPARED ??? struct owner { bool is_active; string name; uint[] ip; } mapping(address => owner) owners; uint owner_count = 0; function CRM(string owner_name, uint[] ip_address) { bytes32[] memory new_owner = new bytes32[](2); owners[msg.sender].is_active = 1; // activate owners[msg.sender].name = owner_name; owners[msg.sender].ip = ip_address; owner_count++; // manual owner count management }
  • 23. THE ONLY WAY TO DELETE - STEP 2 - COST EFFECTIVE UPDATING struct owner { bool is_active; string name; uint[] ip; } mapping(address => owner) owners; uint owner_count = 0; function destroy(address owner_id) { owners[owner_id].is_active = 0; // this costs ether owner_count--; // manual owner count management }
  • 25. CRUDy RECAP - CREATE NEW RECORD contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function create( address user_address, string user_name, string user_email ) onlyOwner public { users[user_address].is_active = 1; users[user_address].name = user_name; users[user_address].email = user_email; } }
  • 26. CRUDy RECAP - READ RECORD contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function read(address user_address) public returns(string user_name, string user_email) { return( users[user_address].name, users[user_address].email ) } }
  • 27. CRUDy RECAP - UPDATE RECORDED DATA BY INDEX contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function update( address user_address, string user_name, string user_email ) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].name = user_name; users[user_address].email = user_email; } }
  • 28. CRUDy RECAP - UPDATE INDEX contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function update_index( address old_address, string new_address ) onlyOwner public { require(users[old_address].is_active == 1); users[new_address].name = users[old_address].name; users[new_address].email = users[old_address].email; users[new_address].is_active = 1; users[old_address].is_active = 0; } }
  • 29. CRUDy RECAP - DESTROY RECORDS contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; function destroy(address user_address) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].is_active = 0; } }
  • 30. CRUDy RECAP - COMPLICATED BY COUNTS contract CRM { struct user { string name; string email; bool is_active; } mapping(address => user) users; uint public user_count; function destroy(address user_address) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].is_active = 0; user_count--; } }
  • 31. CRUDy RECAP - EVEN MORE SO WITH JOINS struct user { string name; string email; bool is_active; uint index_key; } mapping(address => user) users; address[] public user_indexes; function destroy(address user_address) onlyOwner public { require(users[user_address].is_active == 1); users[user_address].is_active = 0; users[user_indexes[user_indexes.length - 1]].index_key = users[user_address].index_key user_indexes[users[user_address].index_key] = user_indexes[user_indexes.length - 1]; user_indexes.length = user_index.length - 1; }
  • 32. CAVEATS - WORKING WITH STRINGS ● Since strings cannot be returned from external contracts every contract dealing with strings needs it own conversion functions ● Converting strings to 32 byte arrays allow anything to be returned - so long as each value is within 32 bytes, which also requires the decoding to be done by the client ● Which brings us to what I thought we would cover today ...
  • 33. WHAT ABOUT CRUD BEYOND PREDEFINED STRUCTURE ??? CREATE READ UPDATE DESTROY
  • 34. TO BE CONTINUED IN PART 2 CREATING A DATABASE WITHIN A CONTRACT
  • 35. email the team anytime - founders@neuroware.io