SlideShare a Scribd company logo
Smart Contracts
using web3.js
Felix Crisan, NETOPIA (mobilPay, web2sms, btko.in)
@fixone / felix@netopia.ro
TGE?
ICO?
Ethereum?
Cryptocurrencies?
Bitcoin?
What all the ICO’s have in
common?
Smart Contracts
● Wikipedia says: “Smart contracts are computer protocols that facilitate, verify, or
enforce the negotiation or performance of a contract, or that make a contractual clause
unnecessary”
● Usually also have a user interface
● Can be verified, enforced, proven by computers
● In MVC terms a smart contract is an environment where the Model is stored on the
blockchain, the View is accessible to anyone by calling public methods or looking at
public variables and the Controller is the contract code itself
● “Code is (the) Law”
There are 3 eras of
currency: Commodity
based, politically based,
and now, math based.
- Chris Dixon
Ethereum support for Smart Contracts
● Contract = code (i.e. functions) and data (its state) that resides at a specific address on
the Ethereum blockchain
● EVM is the runtime for Smart Contracts on Ethereum
● Accounts (thus contracts as well) have a persistent memory area which is called
storage: key-value store that maps 256-bit words to 256-bit words
● Contracts can neither read nor write to any storage apart from its own
● Contracts also have access to memory - linear and can be addressed at byte level
○ Memory is expanded by a 256bits when reading or writing & expansion must be paid in gas
(quadratic scale)
Not all the contracts
deployed on a blockchain
are be smart.
Some are actually dumb.
Ethereum support for Smart Contracts
● Contracts are defined through a transaction sent to 0x000.....000
● Data of the transaction is the compiled contract
● High level languages (for which compilers exist)
○ Solidity (Javascript like)
○ Serpent (Python like)
○ LLL (Lisp like)
● No (real) IDE for contracts - Mix was discontinued, reborn as web-based ReMix
● A couple of options - Atom with atom-ethereum-interface (supports compilation) or
Visual Studio Code (just syntax highlighting)
Ethereum support for Smart Contracts
● Contracts can call other contracts (they can even call themselves)
● 1024 max call stack depth
● call (new contexts) vs delegatecall (same context, e.g. same msg.sender + msg.value)
● Events
● Contracts can purge themselves from the blockchain (OPCODE selfdestruct)
Good to know
● Everything you use in a smart contract is publicly visible, even local variables and state
variables marked private
● If a contract receives Ether (without a function being called), the fallback function is
executed
○ If no fallback function, the Ether is rejected
● Don’t use tx.origin for authorization (use msg.sender)
● Always have a “circuit-breaker”
On the blockchain,
nobody knows you're a
fridge.
-Richard Brown
web3.js
● Official Ethereum JavaScript API
● Wrapper over JSON RPC functionality (available in go-ethereum - geth, parity,
cpp-ethereum, pyethapp)
○ Some RPC modules require explicit activation in order to be available!
● Other API/clients
○ web3j Java https://github.com/web3j/web3j
○ Nethereum C# .NET https://github.com/Nethereum/Nethereum
○ ethereum-ruby Ruby https://github.com/DigixGlobal/ethereum-ruby
● Available
○ on npm as a node module
○ for bower and component as an embeddable js
○ as a meteor.js package.
Web3.js - continued
● Managing accounts
● Signing transactions
● Getting notifications (about certain events)
● Sending of client requests (both asynchronously and synchronously)
● Interaction with Ethereum clients over JSON-RPC
● Auto-generation of Java smart contract function wrappers from Solidity ABI files
web3.js Installation/Usage
Installation
>npm install web3
Usage
var Web3 = require('web3');
var web3 = new Web3();
And then
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
web3.js
● After web3 instantiation all geth modules (specifically enabled over RPC) can be
accessed
● For instance
web3.eth.getBalance(web3.eth.coinbase).toNumber()
web3.personal.listAccounts
console.log(“sha3 is”,web3.sha3(“some string”))
Deployment using a
wallet with GUI
Contract Deployment
● Without any external dependencies : from clients like Mist & Ethereum Wallet
Contract Deployment
After Deployment
This is where you get the ABI interface
Free advice of the day:
not your keys, not your
crypto
… although you don’t
really have private keys,
you merely have
permission from Chuck
Norris to use his (as he
brute-forced all 2256
of
them)
Tools
● Infura.io (so you don’t have to run your own node/s)
● Truffle (w/ local testRPC) http://truffleframework.com/ You can test it without any local
install, from the browser (see e.g.
http://joeysprogrammingblog.com/2015/12/16/ethereum-truffle-and-testrpc-with-clou
d9-2/ )
● Embark https://github.com/iurimatias/embark-framework
● https://openzeppelin.org/
● Online compiler https://remix.ethereum.org/
● Block Explorers
○ Mainnet
■ https://etherscan.io
■ https://etherchain.org
○ Testnet (multiple testnets available ! )
■ https://ropsten.io (POW)
■ https://kovan.etherscan.io/ (POA)
■ https://rinkeby.etherscan.io/ (also POA)
More tools
Get more info
● The Bible: https://ethereum.github.io/yellowpaper/paper.pdf
● But, if you’re an atheist: https://github.com/ethereum/wiki/wiki/JavaScript-API
● http://www.ethdocs.org/en/latest/
● http://solidity.readthedocs.io/en/develop/index.html
● https://crypto.stanford.edu/cs251/syllabus.html (not only on Ether, but great
nonetheless)
All the code for today’s demo
https://github.com/fixone/ethdemo
Smart contracts using web3.js

More Related Content

What's hot

Understanding Blockchain
Understanding BlockchainUnderstanding Blockchain
Understanding Blockchain
Ogilvy Consulting
 
Hyperledger Fabric
Hyperledger FabricHyperledger Fabric
Hyperledger Fabric
Murughan Palaniachari
 
Web3 Infrastructure Thesis
Web3 Infrastructure Thesis Web3 Infrastructure Thesis
Web3 Infrastructure Thesis
SeanStuart17
 
Smart contract
Smart contractSmart contract
Smart contract
Akhmad Daniel Sembiring
 
Blockchain In Government - How The Technology Can Transform Government Services
Blockchain In Government - How The Technology Can Transform Government ServicesBlockchain In Government - How The Technology Can Transform Government Services
Blockchain In Government - How The Technology Can Transform Government Services
Sunil Jagani
 
web3
web3web3
web3
Yoshi
 
The Blockchain - The Technology behind Bitcoin
The Blockchain - The Technology behind Bitcoin The Blockchain - The Technology behind Bitcoin
The Blockchain - The Technology behind Bitcoin
Jérôme Kehrli
 
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
Simplilearn
 
An Investor's Guide to Web3 / Crypto / Blockchain
An Investor's Guide to Web3 / Crypto / BlockchainAn Investor's Guide to Web3 / Crypto / Blockchain
An Investor's Guide to Web3 / Crypto / Blockchain
Bernard Leong
 
Brand New Web3 Wallet
Brand New Web3 WalletBrand New Web3 Wallet
Brand New Web3 Wallet
ssuser7259e6
 
Web3 Full Stack Development
Web3 Full Stack DevelopmentWeb3 Full Stack Development
Web3 Full Stack Development
Gene Leybzon
 
Decentralized Application: A Software Engineering Perspective
Decentralized Application: A Software Engineering PerspectiveDecentralized Application: A Software Engineering Perspective
Decentralized Application: A Software Engineering Perspective
Bambang Purnomosidi D. P.
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
Malak Abu Hammad
 
Blockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricBlockchain - HyperLedger Fabric
Blockchain - HyperLedger Fabric
Araf Karsh Hamid
 
HubCityDAO: Web3 Fundamentals
HubCityDAO: Web3 FundamentalsHubCityDAO: Web3 Fundamentals
HubCityDAO: Web3 Fundamentals
David Barreto
 
Blockchain Presentation
Blockchain PresentationBlockchain Presentation
Blockchain Presentation
Zied GUESMI
 
Ethereum in a nutshell
Ethereum in a nutshellEthereum in a nutshell
Ethereum in a nutshell
Daniel Chan
 
Bitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & BlockchainBitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & Blockchain
Jitendra Chittoda
 
Blockchain, cryptography, and consensus
Blockchain, cryptography, and consensusBlockchain, cryptography, and consensus
Blockchain, cryptography, and consensus
ITU
 

What's hot (20)

Understanding Blockchain
Understanding BlockchainUnderstanding Blockchain
Understanding Blockchain
 
Hyperledger Fabric
Hyperledger FabricHyperledger Fabric
Hyperledger Fabric
 
Web3 Infrastructure Thesis
Web3 Infrastructure Thesis Web3 Infrastructure Thesis
Web3 Infrastructure Thesis
 
Smart contract
Smart contractSmart contract
Smart contract
 
Blockchain In Government - How The Technology Can Transform Government Services
Blockchain In Government - How The Technology Can Transform Government ServicesBlockchain In Government - How The Technology Can Transform Government Services
Blockchain In Government - How The Technology Can Transform Government Services
 
web3
web3web3
web3
 
The Blockchain - The Technology behind Bitcoin
The Blockchain - The Technology behind Bitcoin The Blockchain - The Technology behind Bitcoin
The Blockchain - The Technology behind Bitcoin
 
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
Blockchain Interview Questions And Answers | Blockchain Technology Interview ...
 
An Investor's Guide to Web3 / Crypto / Blockchain
An Investor's Guide to Web3 / Crypto / BlockchainAn Investor's Guide to Web3 / Crypto / Blockchain
An Investor's Guide to Web3 / Crypto / Blockchain
 
Brand New Web3 Wallet
Brand New Web3 WalletBrand New Web3 Wallet
Brand New Web3 Wallet
 
Web3 Full Stack Development
Web3 Full Stack DevelopmentWeb3 Full Stack Development
Web3 Full Stack Development
 
Decentralized Application: A Software Engineering Perspective
Decentralized Application: A Software Engineering PerspectiveDecentralized Application: A Software Engineering Perspective
Decentralized Application: A Software Engineering Perspective
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
 
Blockchain - HyperLedger Fabric
Blockchain - HyperLedger FabricBlockchain - HyperLedger Fabric
Blockchain - HyperLedger Fabric
 
HubCityDAO: Web3 Fundamentals
HubCityDAO: Web3 FundamentalsHubCityDAO: Web3 Fundamentals
HubCityDAO: Web3 Fundamentals
 
Blockchain Presentation
Blockchain PresentationBlockchain Presentation
Blockchain Presentation
 
Ethereum in a nutshell
Ethereum in a nutshellEthereum in a nutshell
Ethereum in a nutshell
 
Blockchain
BlockchainBlockchain
Blockchain
 
Bitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & BlockchainBitcoin, Ethereum, Smart Contract & Blockchain
Bitcoin, Ethereum, Smart Contract & Blockchain
 
Blockchain, cryptography, and consensus
Blockchain, cryptography, and consensusBlockchain, cryptography, and consensus
Blockchain, cryptography, and consensus
 

Similar to Smart contracts using web3.js

Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in Solidity
Felix Crisan
 
Ethereum
EthereumEthereum
Ethereum
Brian Yap
 
How to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contractHow to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contract
Joseph Holbrook, Chief Learning Officer (CLO)
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contracts
Gautam Anand
 
Building Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart ContractBuilding Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart Contract
Vaideeswaran Sethuraman
 
Fluent destry saul
Fluent destry saulFluent destry saul
Fluent destry saul
Destry Saul
 
Token platform based on sidechain
Token platform based on sidechainToken platform based on sidechain
Token platform based on sidechain
Luniverse Dunamu
 
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion
 
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion
 
Introduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptx
Gene Leybzon
 
Daniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's ThesisDaniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly
 
Web3 Security: The Blockchain is Your SIEM
Web3 Security: The Blockchain is Your SIEMWeb3 Security: The Blockchain is Your SIEM
Web3 Security: The Blockchain is Your SIEM
Tal Be'ery
 
A living programming environment for blockchain
A living programming environment for blockchainA living programming environment for blockchain
A living programming environment for blockchain
Pharo
 
A living programming environment for a living blockchain
A living programming environment for a living blockchainA living programming environment for a living blockchain
A living programming environment for a living blockchain
Santiago Bragagnolo
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
All Things Open
 
Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts
ArcBlock
 
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Codemotion
 
Blockchain Explorer
Blockchain ExplorerBlockchain Explorer
Blockchain Explorer
Rihusoft
 
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitWeb3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Tal Be'ery
 
Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)
Tomoaki Sato
 

Similar to Smart contracts using web3.js (20)

Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in Solidity
 
Ethereum
EthereumEthereum
Ethereum
 
How to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contractHow to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contract
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contracts
 
Building Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart ContractBuilding Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart Contract
 
Fluent destry saul
Fluent destry saulFluent destry saul
Fluent destry saul
 
Token platform based on sidechain
Token platform based on sidechainToken platform based on sidechain
Token platform based on sidechain
 
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
 
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
 
Introduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptx
 
Daniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's ThesisDaniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's Thesis
 
Web3 Security: The Blockchain is Your SIEM
Web3 Security: The Blockchain is Your SIEMWeb3 Security: The Blockchain is Your SIEM
Web3 Security: The Blockchain is Your SIEM
 
A living programming environment for blockchain
A living programming environment for blockchainA living programming environment for blockchain
A living programming environment for blockchain
 
A living programming environment for a living blockchain
A living programming environment for a living blockchainA living programming environment for a living blockchain
A living programming environment for a living blockchain
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
 
Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts
 
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
 
Blockchain Explorer
Blockchain ExplorerBlockchain Explorer
Blockchain Explorer
 
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitWeb3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
 
Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)
 

More from Felix Crisan

Big data uservices
Big data uservicesBig data uservices
Big data uservices
Felix Crisan
 
Bitcoin:Next
Bitcoin:NextBitcoin:Next
Bitcoin:Next
Felix Crisan
 
BigData in BlockChains
BigData in BlockChainsBigData in BlockChains
BigData in BlockChains
Felix Crisan
 
Lightning Network
Lightning  NetworkLightning  Network
Lightning Network
Felix Crisan
 
Mashing the data
Mashing the dataMashing the data
Mashing the data
Felix Crisan
 
Big(data) in block(chains)
Big(data) in block(chains)Big(data) in block(chains)
Big(data) in block(chains)
Felix Crisan
 
Enablers for o commerce
Enablers for o commerceEnablers for o commerce
Enablers for o commerce
Felix Crisan
 
mcommad
mcommadmcommad
mcommad
Felix Crisan
 
NoSQL solutions
NoSQL solutionsNoSQL solutions
NoSQL solutions
Felix Crisan
 
Deconstructing Lambda architectures
Deconstructing Lambda architecturesDeconstructing Lambda architectures
Deconstructing Lambda architectures
Felix Crisan
 
402 @ Mobile next
402 @ Mobile next402 @ Mobile next
402 @ Mobile next
Felix Crisan
 
Presentation for the first Bucharest Big data meetup
Presentation for the first Bucharest Big data meetupPresentation for the first Bucharest Big data meetup
Presentation for the first Bucharest Big data meetup
Felix Crisan
 
Data analysis with Pandas and Spark
Data analysis with Pandas and SparkData analysis with Pandas and Spark
Data analysis with Pandas and Spark
Felix Crisan
 
TCP/IP of money
TCP/IP of moneyTCP/IP of money
TCP/IP of money
Felix Crisan
 

More from Felix Crisan (14)

Big data uservices
Big data uservicesBig data uservices
Big data uservices
 
Bitcoin:Next
Bitcoin:NextBitcoin:Next
Bitcoin:Next
 
BigData in BlockChains
BigData in BlockChainsBigData in BlockChains
BigData in BlockChains
 
Lightning Network
Lightning  NetworkLightning  Network
Lightning Network
 
Mashing the data
Mashing the dataMashing the data
Mashing the data
 
Big(data) in block(chains)
Big(data) in block(chains)Big(data) in block(chains)
Big(data) in block(chains)
 
Enablers for o commerce
Enablers for o commerceEnablers for o commerce
Enablers for o commerce
 
mcommad
mcommadmcommad
mcommad
 
NoSQL solutions
NoSQL solutionsNoSQL solutions
NoSQL solutions
 
Deconstructing Lambda architectures
Deconstructing Lambda architecturesDeconstructing Lambda architectures
Deconstructing Lambda architectures
 
402 @ Mobile next
402 @ Mobile next402 @ Mobile next
402 @ Mobile next
 
Presentation for the first Bucharest Big data meetup
Presentation for the first Bucharest Big data meetupPresentation for the first Bucharest Big data meetup
Presentation for the first Bucharest Big data meetup
 
Data analysis with Pandas and Spark
Data analysis with Pandas and SparkData analysis with Pandas and Spark
Data analysis with Pandas and Spark
 
TCP/IP of money
TCP/IP of moneyTCP/IP of money
TCP/IP of money
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 

Recently uploaded (20)

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 

Smart contracts using web3.js

  • 1. Smart Contracts using web3.js Felix Crisan, NETOPIA (mobilPay, web2sms, btko.in) @fixone / felix@netopia.ro
  • 6.
  • 8. What all the ICO’s have in common?
  • 9. Smart Contracts ● Wikipedia says: “Smart contracts are computer protocols that facilitate, verify, or enforce the negotiation or performance of a contract, or that make a contractual clause unnecessary” ● Usually also have a user interface ● Can be verified, enforced, proven by computers ● In MVC terms a smart contract is an environment where the Model is stored on the blockchain, the View is accessible to anyone by calling public methods or looking at public variables and the Controller is the contract code itself ● “Code is (the) Law”
  • 10. There are 3 eras of currency: Commodity based, politically based, and now, math based. - Chris Dixon
  • 11. Ethereum support for Smart Contracts ● Contract = code (i.e. functions) and data (its state) that resides at a specific address on the Ethereum blockchain ● EVM is the runtime for Smart Contracts on Ethereum ● Accounts (thus contracts as well) have a persistent memory area which is called storage: key-value store that maps 256-bit words to 256-bit words ● Contracts can neither read nor write to any storage apart from its own ● Contracts also have access to memory - linear and can be addressed at byte level ○ Memory is expanded by a 256bits when reading or writing & expansion must be paid in gas (quadratic scale)
  • 12. Not all the contracts deployed on a blockchain are be smart. Some are actually dumb.
  • 13. Ethereum support for Smart Contracts ● Contracts are defined through a transaction sent to 0x000.....000 ● Data of the transaction is the compiled contract ● High level languages (for which compilers exist) ○ Solidity (Javascript like) ○ Serpent (Python like) ○ LLL (Lisp like) ● No (real) IDE for contracts - Mix was discontinued, reborn as web-based ReMix ● A couple of options - Atom with atom-ethereum-interface (supports compilation) or Visual Studio Code (just syntax highlighting)
  • 14. Ethereum support for Smart Contracts ● Contracts can call other contracts (they can even call themselves) ● 1024 max call stack depth ● call (new contexts) vs delegatecall (same context, e.g. same msg.sender + msg.value) ● Events ● Contracts can purge themselves from the blockchain (OPCODE selfdestruct)
  • 15. Good to know ● Everything you use in a smart contract is publicly visible, even local variables and state variables marked private ● If a contract receives Ether (without a function being called), the fallback function is executed ○ If no fallback function, the Ether is rejected ● Don’t use tx.origin for authorization (use msg.sender) ● Always have a “circuit-breaker”
  • 16. On the blockchain, nobody knows you're a fridge. -Richard Brown
  • 17. web3.js ● Official Ethereum JavaScript API ● Wrapper over JSON RPC functionality (available in go-ethereum - geth, parity, cpp-ethereum, pyethapp) ○ Some RPC modules require explicit activation in order to be available! ● Other API/clients ○ web3j Java https://github.com/web3j/web3j ○ Nethereum C# .NET https://github.com/Nethereum/Nethereum ○ ethereum-ruby Ruby https://github.com/DigixGlobal/ethereum-ruby ● Available ○ on npm as a node module ○ for bower and component as an embeddable js ○ as a meteor.js package.
  • 18. Web3.js - continued ● Managing accounts ● Signing transactions ● Getting notifications (about certain events) ● Sending of client requests (both asynchronously and synchronously) ● Interaction with Ethereum clients over JSON-RPC ● Auto-generation of Java smart contract function wrappers from Solidity ABI files
  • 19. web3.js Installation/Usage Installation >npm install web3 Usage var Web3 = require('web3'); var web3 = new Web3(); And then web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
  • 20. web3.js ● After web3 instantiation all geth modules (specifically enabled over RPC) can be accessed ● For instance web3.eth.getBalance(web3.eth.coinbase).toNumber() web3.personal.listAccounts console.log(“sha3 is”,web3.sha3(“some string”))
  • 22. Contract Deployment ● Without any external dependencies : from clients like Mist & Ethereum Wallet
  • 24. After Deployment This is where you get the ABI interface
  • 25. Free advice of the day: not your keys, not your crypto
  • 26. … although you don’t really have private keys, you merely have permission from Chuck Norris to use his (as he brute-forced all 2256 of them)
  • 27. Tools ● Infura.io (so you don’t have to run your own node/s) ● Truffle (w/ local testRPC) http://truffleframework.com/ You can test it without any local install, from the browser (see e.g. http://joeysprogrammingblog.com/2015/12/16/ethereum-truffle-and-testrpc-with-clou d9-2/ ) ● Embark https://github.com/iurimatias/embark-framework ● https://openzeppelin.org/
  • 28. ● Online compiler https://remix.ethereum.org/ ● Block Explorers ○ Mainnet ■ https://etherscan.io ■ https://etherchain.org ○ Testnet (multiple testnets available ! ) ■ https://ropsten.io (POW) ■ https://kovan.etherscan.io/ (POA) ■ https://rinkeby.etherscan.io/ (also POA) More tools
  • 29. Get more info ● The Bible: https://ethereum.github.io/yellowpaper/paper.pdf ● But, if you’re an atheist: https://github.com/ethereum/wiki/wiki/JavaScript-API ● http://www.ethdocs.org/en/latest/ ● http://solidity.readthedocs.io/en/develop/index.html ● https://crypto.stanford.edu/cs251/syllabus.html (not only on Ether, but great nonetheless)
  • 30. All the code for today’s demo https://github.com/fixone/ethdemo