Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Ethereum Developers
Community
Smart Contract Tutorial
Arnold Pham
Cofounder of Lunyr
www.linkedin.com/in/arnoldpham
Unless...
High level view of web app client server architecture
High level view of Ethereum Dapp Architecture
Yikes! Downloading the whole blockchain?
EVM - Database and Code
Built in financial system
Solidity
Useful Tools - Opportunities for contribution
ethereumjs-testrpc
• Node.js based Ethereum client for testing and developme...
Browser-Solidity
Shows errors
Creating Contracts
What is the ABI?
Application Binary Interface
Deploying a Contract with Web3
1. Write your contract
2. Make sure you have the Solidity compiler
No Solidity compiler? Proceed to next step
Download https://github.com/ethereu...
3. Compile your contract with web3.eth.compile.solidity(source) to get an
object with the contract and compiler info
You need the abiDefinition
Create a contract object which can be used to
instantiate contracts on an address
Deploy the Contract
var contractInstance = MyContract.new([contructorParam1] [, contructorParam2], {data: '0x12345...', fr...
Contract mined!
Check transactionHash
transactionHash: 0x87e42f5a325e13736342ce0d8e505e332b3ee20a5aa0c6f1080c0d5df8a0f1ab
You can also check that the contract was deployed at the address with:
eth.getCode(simplestorage.address)
Contract Address...
1. Write your contract
Retrieving Data from the simplestorage Contract
instance
> simplestorage.get ()
Method calls with sendTransaction
contractInstance.method.sendTransaction([parameter], { from: eth.accounts[0])
Change storedData to 20. simplestorage.get() to
view change
> simplestorage.set.sendTransaction(20, {from: eth.accounts[0]...
Getting other people to interact with your code
Requires the ABI
Then they can instantiate a Javascript object which can b...
Deploying a Contract with Browser-Solidity
Write the contract in Browser-Solidity
Uses Metamask. Spend Ether to deploy it
Now on blockchain
Etherscan Block Explorer shows the contract
ERC20 Specification
Token Methods:
totalSupply
balanceOf
transfer
transferFrom
approve
allowance
Creating a simple token contract
(Warning: Very simplified Example)
The Token Contract
Steps to deploy the contract
> var tokenSource = 'contract Token{address public owner;mapping(address=>uint)balances;funct...
> var tokenCompiled = web3.eth.compile.solidity(tokenSource)
> var tokenContract = web3.eth.contract(tokenCompiled.Token.info.abiDefinition)
Create new instance
Check the owner
GetBalance
Transfer tokens to another address
Thank you for watching! Stay tuned for more!
Prochain SlideShare
Chargement dans…5
×

Ethereum Smart Contract Tutorial

5 156 vues

Publié le

Tutorial on writing, using, and deploying smart contracts

Publié dans : Internet
  • Soyez le premier à commenter

Ethereum Smart Contract Tutorial

  1. 1. Ethereum Developers Community Smart Contract Tutorial Arnold Pham Cofounder of Lunyr www.linkedin.com/in/arnoldpham Unless otherwise stated, these slides are licensed under the Creative Commons Attribution-NonCommercial 3.0 License (https://creativecommons.org/licenses/by-nc/3.0/us/)
  2. 2. High level view of web app client server architecture
  3. 3. High level view of Ethereum Dapp Architecture
  4. 4. Yikes! Downloading the whole blockchain?
  5. 5. EVM - Database and Code
  6. 6. Built in financial system
  7. 7. Solidity
  8. 8. Useful Tools - Opportunities for contribution ethereumjs-testrpc • Node.js based Ethereum client for testing and development • Simulates full client behavior • https://github.com/ethereumjs/testrpc dapple • developer multitool for managing the growing complexity of interconnected smart contract systems • https://github.com/nexusdev/dapple truffle • A development environment, testing framework and asset pipeline for Ethereum
  9. 9. Browser-Solidity
  10. 10. Shows errors
  11. 11. Creating Contracts
  12. 12. What is the ABI? Application Binary Interface
  13. 13. Deploying a Contract with Web3
  14. 14. 1. Write your contract
  15. 15. 2. Make sure you have the Solidity compiler No Solidity compiler? Proceed to next step Download https://github.com/ethereum/solidity/releases
  16. 16. 3. Compile your contract with web3.eth.compile.solidity(source) to get an object with the contract and compiler info
  17. 17. You need the abiDefinition
  18. 18. Create a contract object which can be used to instantiate contracts on an address
  19. 19. Deploy the Contract var contractInstance = MyContract.new([contructorParam1] [, contructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000}); Make sure to unlock the account first with personal.unlockAccount(eth.accounts[0])
  20. 20. Contract mined!
  21. 21. Check transactionHash
  22. 22. transactionHash: 0x87e42f5a325e13736342ce0d8e505e332b3ee20a5aa0c6f1080c0d5df8a0f1ab
  23. 23. You can also check that the contract was deployed at the address with: eth.getCode(simplestorage.address) Contract Address: "0xeb2186b9f667796497f0fc3c824d0bb57a548c25"
  24. 24. 1. Write your contract
  25. 25. Retrieving Data from the simplestorage Contract instance > simplestorage.get ()
  26. 26. Method calls with sendTransaction contractInstance.method.sendTransaction([parameter], { from: eth.accounts[0])
  27. 27. Change storedData to 20. simplestorage.get() to view change > simplestorage.set.sendTransaction(20, {from: eth.accounts[0]})
  28. 28. Getting other people to interact with your code Requires the ABI Then they can instantiate a Javascript object which can be used to call the contract from any node on the network var newInstance = eth.contract(ABI).at(Address);
  29. 29. Deploying a Contract with Browser-Solidity
  30. 30. Write the contract in Browser-Solidity
  31. 31. Uses Metamask. Spend Ether to deploy it
  32. 32. Now on blockchain
  33. 33. Etherscan Block Explorer shows the contract
  34. 34. ERC20 Specification Token Methods: totalSupply balanceOf transfer transferFrom approve allowance
  35. 35. Creating a simple token contract (Warning: Very simplified Example)
  36. 36. The Token Contract
  37. 37. Steps to deploy the contract > var tokenSource = 'contract Token{address public owner;mapping(address=>uint)balances;function Token(){owner=msg.sender;balances[owner]=100;}function transfer(address _to,uint _value)returns(bool success){if(balances[msg.sender]<_value){return false;}balances[msg.sender]-=_value;balances[_to]+=_value;return true;}function getBalance(address _user)constant returns(uint _balance){return balances[_user];}}'
  38. 38. > var tokenCompiled = web3.eth.compile.solidity(tokenSource)
  39. 39. > var tokenContract = web3.eth.contract(tokenCompiled.Token.info.abiDefinition)
  40. 40. Create new instance
  41. 41. Check the owner
  42. 42. GetBalance
  43. 43. Transfer tokens to another address
  44. 44. Thank you for watching! Stay tuned for more!

×