Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Ethereummeetuppresentation01 170105172132
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/)
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
18. Create a contract object which can be used to
instantiate contracts on an address
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])
23. You can also check that the contract was deployed at the address with:
eth.getCode(simplestorage.address)
Contract Address: "0xeb2186b9f667796497f0fc3c824d0bb57a548c25"
26. Method calls with sendTransaction
contractInstance.method.sendTransaction([parameter], { from: eth.accounts[0])
27. Change storedData to 20. simplestorage.get() to
view change
> simplestorage.set.sendTransaction(20, {from: eth.accounts[0]})
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);
If you are a web developer, you know how a webapp with it’s client server architecture works at a very high level.
You have your web application hosted on a hosting provider like AWS, Heroku or a VPS. All the clients interact with this one central application. Clients can be a browser, another api consuming your service etc. When a client makes a request to the server, the server does it’s magic, talks to the database and/or cache, reads/writes/updates the database and serves the client.
https://medium.com/@mvmurthy/ethereum-for-web-developers-890be23d1d0c#.l6ucyhvl0
If you notice, every client (browser) communicates with it’s own instance of the application. There is no central server to which all clients connect to. This means, every person who wants to interact with a dapp (Decentralized Application) will need a full copy of the blockchain running on their computer/phone etc. That means, before you can use an application, you have to download the entire blockchain and then start using the application. This is currently changing with the continued development of “light” clients which will enable users in low-capacity environments to receive data from the network about parts of the state without downloading the blockchain in its entirety
https://medium.com/@mvmurthy/ethereum-for-web-developers-890be23d1d0c#.l6ucyhvl0
In reality, you aren’t really using all of your storage and RAM downloading the entire blockchain. There are optimizations and technical advancements within Ethereum improving the efficiency
The Ethereum blockchain can be thought of as a world Database and Code base. The Ethereum Virtual Machine (EVM) stores your data, stores the code, and runs the code in the EVM
A special capability of Ethereum is it has a built in financial system. You create bank accounts at a fraction of a second. These accounts store a cryptocurrency called Ether which you can send to other accounts on Ethereum
The high-level language used in Ethereum for writing contracts. Javascript-like with strong variable types
Useful tool
Shows errors
The contract are stored as bytecode in a binary form into the blockchain under a specific address. The ABI defines the structures and methods that you will use to interact with binary contract (just like the API did), only on a lower level. You can accesses the binary data in the contract through the ABI. In ethereum, the ABI is how you can encode solidity contracts for the EVM and backwards how to read the data out of transactions.
Since we’re working inside the geth console, we don’t need to use web3.eth and can just write eth.
Compile your contract in Browser-Solidity or use web3.eth.compile.solidity(source)
var simpleStorageCompiled = web3.eth.compile.solidity(simpleStorageSource)
var simpleStorageContract = web3.eth.contract(simpleStorageCompiled.SimpleStorage.info.abiDefinition)
Gets you a contract object
Deploy the contract and check if it was mined using the transactionHash
Check Transaction Hash on Ropsten Testnet. 2 Block confirmations
Compile your contract in Browser-Solidity or use web3.eth.compile.solidity(source)
After calling the set method
You can see the bytecode of the contract and the ABI. There isn’t anything to interact with in this. Write your code. Then click Create.
Metamask will popup and ask you if you’d like to accept or reject the transaction. Ignore the Transaction Error, it’s a current bug with Browser-Solidity and metamask when confirming transactions but
everything works fine. You can still compile, create the contract, and run transactions
Get the total token supply
Get the account balance of another account with address _owner
Send _value amount of tokens to address _to
Send _value amount of tokens from address _from to address _to
Allow _spender to withdraw from your account, multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value.
Returns the amount which _spender is still allowed to withdraw from _owner