【比特币】 From P2SH of bitcoin to Smart Contract of ethereum
2017-10-17 17:28
429 查看
Ethereum: Smart Contract
Aug. 23, 2016
Turing-Complete VM
Uncle blocks strengthen
Turing Complete Script
State Storage mounted
SPV (skipped)
Smart Contract need more states be recorded in blockchains.
- https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options
Web3:
- https://github.com/ethereum/wiki/wiki/JavaScript-API
Console or RPC
- http://ethdocs.org/en/latest/contracts-and-transactions/contracts.html
- https://ethereum.gitbooks.io/frontier-guide/content/sending_ether.html
compile:
TODO:
more inspections on test_Contract;
Note:
To deploy a contract requires payment to miners, so remeber to personal.unlockAccout().
- http://ethereum.stackexchange.com/questions/6870/create-a-new-contract-by-json-rpc-of-cpp-ethereum
Note:
This is very like the P2SH, and ehtereum is evolved from this feature of bitcoin.
Contract address
ABI
sample:
https://www.ethereum.org/greeter
Note:
1) deploy the contract code.
2) invoke the Constructor with initialization paramters list.
gas estimate
Web3 API Impl.
Inside contract lifetime
contract global registration
on reading this snap text from the book: data insertion in bitcoin’s blockchain:
while reading the second claim, i feel very superised, but then the author say about “least expensive”, i get relaxed.
Aug. 23, 2016
Core Concepts:
MPT state and storageTuring-Complete VM
New features:
Gas Limit and NO Free TransactionsUncle blocks strengthen
Turing Complete Script
State Storage mounted
Motivations:
color-ed coins ( compare later)SPV (skipped)
Limit on color-ed coins of bitcoin
From UTXOs to State Database
Bitcoin blockchain is a database of UTXOs, in fact.Smart Contract need more states be recorded in blockchains.
APIs of ethereum
Command line options:- https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options
Web3:
- https://github.com/ethereum/wiki/wiki/JavaScript-API
Console or RPC
- http://ethdocs.org/en/latest/contracts-and-transactions/contracts.html
Experiment: new account
$ geth --datadir ./node1 account new > Address: {ed0340bb8ac2d79aec6156d2c383a8f89ce13686}
$ geth --datadir ./node1 init genesis.json
Experiment: genesis.json
{ "nonce": "0x0000000000000042", "timestamp": "0x0", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x0", "gasLimit": "0x8000000", "difficulty": "0x400", "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x3333333333333333333333333333333333333333", "alloc": { "0xffffffffffffffffffff" : { "balance" : "10000000000000000000" } } }
Experiment: mining with low difficulty
Experiment: basic transfer
Ref:- https://ethereum.gitbooks.io/frontier-guide/content/sending_ether.html
> var sender = eth.accounts[0]; > var receiver = eth.accounts[1]; > var amount = web3.toWei(0.01, "ether") > eth.sendTransaction({from:sender, to:receiver, value: amount})
Experiment: compile a contract with solidity
sample: multiplycontract test { function multiply(uint a) returns(uint d) { return a * 7; } }
compile:
var test_Contract = eth.compile.solidity(source);
TODO:
more inspections on test_Contract;
Experiment: Burn gas to deploy contract
Essentialy deploying a contract is to sendTransaction - to : <must absent> - code: byte code of compiled contract - from: address of contract creator
Note:
To deploy a contract requires payment to miners, so remeber to personal.unlockAccout().
- http://ethereum.stackexchange.com/questions/6870/create-a-new-contract-by-json-rpc-of-cpp-ethereum
Note:
This is very like the P2SH, and ehtereum is evolved from this feature of bitcoin.
Experiment: call contract
Prerequisites to call a contract:Contract address
ABI
sample:
>eth.getTransactionReceipt('0xb31cc6169ceb2db952749eb89f1a965eee0ca8de8f656633d9c6195fa01f2f59').contractAddress >var contract_address = "0xb63897f156cef728279b461663286c11c8866ff1". >var abi = [{constant: false, inputs: [{name: 'a', type: 'unit256'}]}]; > var c = web3.eth.contract(constract_abi); > var obj = c.at(contract_address); > var arg1 = 3; > var my_acccount_address = '0x2773ffb039ded4bd86c3c96bf136e9f2bf510114'; > obj.multiply.sendTransaction(arg1, {from: my_account_address});
Experiment: a contract instance with constructor
Construct a contract instance with parameters and deploy this instance on the blockchain.https://www.ethereum.org/greeter
Note:
1) deploy the contract code.
2) invoke the Constructor with initialization paramters list.
TODO:
MPT state & storage treegas estimate
Web3 API Impl.
Inside contract lifetime
contract global registration
on reading this snap text from the book: data insertion in bitcoin’s blockchain:
It is common knowledge that extrinsic data can be stored in the Blockchain, and there are numerous websites that provide access to a subset of that data,51–53 and some excellent sleuthing has uncovered a variety of interesting historical artifacts that have previously been stored.54 Nevertheless, there remains confusion and misinformation about the variety of different methods by which data can be (and has been) stored. For instance, a recent comprehensive textbook on Bitcoin included the following: “There’s no good way to prevent people from writing arbitrary data into the Bitcoin block chain [sic]. One possible countermeasure is to only accept Pay-to-Script-Hash transactions. This would make it a bit more expensive to write in arbitrary data, but it still wouldn’t prevent it.”55 The first claim, that one cannot prevent arbitrary data insertion, is correct, since there is no general way to distinguish between legitimate address hashes and arbitrary binary data. However, the second claim is false, as P2SH (Pay-to-Script-Hash) transactions actually provide the least expensive and most efficient method for storing large amounts of arbitrary data (see section 5).
while reading the second claim, i feel very superised, but then the author say about “least expensive”, i get relaxed.
相关文章推荐
- how to find list of possible words from letter matrix
- A brief introduction to XenBus from the perspective of the driver
- 解决cast from 'char*' to 'char**' increases required alignment of target type [-Werror=cast-align]
- How to Get Rid of /wordpress/ From your WordPress Site URL
- Notes of Introduction to OS Abstractions Using Plan 9 from Bell Labs(I)
- From double Click to Main: The initialization of Process in OS
- 1. 青蛙跳跳FrogJmp Count minimal number of jumps from position X to Y.
- High Scalability - High Scalability - Scaling Pinterest - From 0 to 10s of Billions of Page Views a Month in Two Years
- -[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x7fa5216589d0
- Porting of cURL to Android OS using NDK (from The Software Rogue)
- From feature descriptors to deep learning: 20 years of computer vision
- Exception: Operation xx of contract xx specifies multiple request body parameters to be serialized without any wrapper elements.
- From the documentation of -[NSArray indexOfObjectIdenticalTo:]
- 69.You need to generate a list of all customer last names with their credit limits from the CUSTOMER
- the limit to the amount of thread from a process
- Java解决No enclosing instance of type PrintListFromTailToHead is accessible问题
- pass all options of <select> from View to controller
- warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
- Top Ten Cool Features of Visual Studio .NET Help You Go From Geek to Guru
- get the nsum of 'Fibonacci'from one to twenty