SlideShare a Scribd company logo
1 of 31
Download to read offline
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

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 / BlockchainBernard Leong
 
Web3 Infrastructure Thesis
Web3 Infrastructure Thesis Web3 Infrastructure Thesis
Web3 Infrastructure Thesis SeanStuart17
 
Block chain 101 what it is, why it matters
Block chain 101  what it is, why it mattersBlock chain 101  what it is, why it matters
Block chain 101 what it is, why it mattersPaul Brody
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to BlockchainMalak Abu Hammad
 
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Edureka!
 
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...Edureka!
 
Brand New Web3 Wallet
Brand New Web3 WalletBrand New Web3 Wallet
Brand New Web3 Walletssuser7259e6
 
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Simplilearn
 
Blockchain Technology ppt project.pptx
Blockchain Technology ppt project.pptxBlockchain Technology ppt project.pptx
Blockchain Technology ppt project.pptxSahilBansal648873
 
Blockchain Technology and Its Application in Libraries
Blockchain Technology and Its Application in LibrariesBlockchain Technology and Its Application in Libraries
Blockchain Technology and Its Application in LibrariesNabi Hasan
 
Understanding blockchain
Understanding blockchainUnderstanding blockchain
Understanding blockchainPriyab Satoshi
 
Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?Fermat Jade
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to BlockchainJordan Harris
 
Blockchain Technology Fundamentals
Blockchain Technology FundamentalsBlockchain Technology Fundamentals
Blockchain Technology FundamentalsExperfy
 
Basic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgersBasic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgersKoen Vingerhoets
 
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...Edureka!
 
How does blockchain work
How does blockchain workHow does blockchain work
How does blockchain workShishir Aryal
 

What's hot (20)

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
 
Blockchain concepts
Blockchain conceptsBlockchain concepts
Blockchain concepts
 
Web3 Infrastructure Thesis
Web3 Infrastructure Thesis Web3 Infrastructure Thesis
Web3 Infrastructure Thesis
 
Block chain 101 what it is, why it matters
Block chain 101  what it is, why it mattersBlock chain 101  what it is, why it matters
Block chain 101 what it is, why it matters
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
 
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
Blockchain 101 | Blockchain Tutorial | Blockchain Smart Contracts | Blockchai...
 
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
Blockchain Explained | Blockchain Simplified | Blockchain Technology | Blockc...
 
Brand New Web3 Wallet
Brand New Web3 WalletBrand New Web3 Wallet
Brand New Web3 Wallet
 
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
Ethereum Tutorial - Ethereum Explained | What is Ethereum? | Ethereum Explain...
 
Blockchain Technology ppt project.pptx
Blockchain Technology ppt project.pptxBlockchain Technology ppt project.pptx
Blockchain Technology ppt project.pptx
 
Blockchain Technology and Its Application in Libraries
Blockchain Technology and Its Application in LibrariesBlockchain Technology and Its Application in Libraries
Blockchain Technology and Its Application in Libraries
 
Understanding blockchain
Understanding blockchainUnderstanding blockchain
Understanding blockchain
 
Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?Blockchain Study(1) - What is Blockchain?
Blockchain Study(1) - What is Blockchain?
 
Blockchain
BlockchainBlockchain
Blockchain
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
 
Blockchain Technology Fundamentals
Blockchain Technology FundamentalsBlockchain Technology Fundamentals
Blockchain Technology Fundamentals
 
Basic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgersBasic introduction in blockchain, smart contracts, permissioned ledgers
Basic introduction in blockchain, smart contracts, permissioned ledgers
 
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
Blockchain Technology | Blockchain Explained | Blockchain Tutorial | Blockcha...
 
Blockchain 2.0
Blockchain 2.0Blockchain 2.0
Blockchain 2.0
 
How does blockchain work
How does blockchain workHow does blockchain work
How does blockchain work
 

Similar to Smart contracts using web3.js

Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in SolidityFelix Crisan
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsTechracers
 
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 contractsGautam Anand
 
Building Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart ContractBuilding Apps with Ethereum Smart Contract
Building Apps with Ethereum Smart ContractVaideeswaran Sethuraman
 
Fluent destry saul
Fluent destry saulFluent destry saul
Fluent destry saulDestry Saul
 
Token platform based on sidechain
Token platform based on sidechainToken platform based on sidechain
Token platform based on sidechainLuniverse 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 2018Codemotion
 
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 2018Codemotion
 
Blockchain architected
Blockchain architectedBlockchain architected
Blockchain architectedIBM Sverige
 
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).pptxGene 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 ThesisDaniel 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 SIEMTal Be'ery
 
A living programming environment for blockchain
A living programming environment for blockchainA living programming environment for blockchain
A living programming environment for blockchainPharo
 
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 blockchainSantiago 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 ContractAll 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 2018Codemotion
 

Similar to Smart contracts using web3.js (20)

Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in Solidity
 
Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
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
 
Blockchain architected
Blockchain architectedBlockchain architected
Blockchain architected
 
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
 

More from Felix Crisan

Big data uservices
Big data uservicesBig data uservices
Big data uservicesFelix Crisan
 
BigData in BlockChains
BigData in BlockChainsBigData in BlockChains
BigData in BlockChainsFelix 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 commerceFelix Crisan
 
Deconstructing Lambda architectures
Deconstructing Lambda architecturesDeconstructing Lambda architectures
Deconstructing Lambda architecturesFelix 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 meetupFelix Crisan
 
Data analysis with Pandas and Spark
Data analysis with Pandas and SparkData analysis with Pandas and Spark
Data analysis with Pandas and SparkFelix 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

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

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