ethereum smart contract 基本

uint256 => 2^256 byte32 => 2^8^32 (byte=2^8) or 32個byte 放32字元(ascii) 0x => HEX 16進位 0x64 => 6 * (16^1) + 4 * (16^0) = 100 0x0164 => 1 * (16^2) + 6 * (16^1) + 4 * (16^0) = 365 0x HEX 16進位 最小0 最大F 回到最上面byte32 轉成 0x HEX 為了避免太長,2^8 = 256 => 16^2 => 16位元顯示要兩位 0256 => 00FF || FF => 15 * (16^1) + 15 * (16^0) 所以 0x0164,通常都是兩位處理 0x 01 64 ...

2019-05-30 · 2 min · 408 words · Me

[轉][Solidity] 壓縮智能合約的輸入資料

https://medium.com/joyso/solidity-%E5%A3%93%E7%B8%AE%E6%99%BA%E8%83%BD%E5%90%88%E7%B4%84%E7%9A%84%E8%BC%B8%E5%85%A5%E8%B3%87%E6%96%99-65a870d1f04e

2019-05-30 · 1 min · word · Me

ethereum smart contract private value not safe

https://hackernoon.com/your-private-solidity-variable-is-not-private-save-it-before-it-becomes-public-52a723f29f5e 上面範例中,play(100)被呼叫後,從transcation data內得知 0x6587f6ec0000000000000000000000000000000000000000000000000000000000000064 然後先取得play()這部份的data bytes4(keccak256(‘play(uint)’)) 然後得知 0000000000000000000000000000000000000000000000000000000000000064 就是 uint部份,得到的這個值是經過hex才顯示的 byte32:00 為1個byte(16 bits),共32個 64=> 6 * (16^1) + 4 * (16^0) = 100 uint256 => 2^256 => 8^32 => byte32

2019-05-30 · 1 min · 30 words · Me

ethereum blockscout

https://github.com/poanetwork/blockscout/tree/master/docker

2019-05-29 · 1 min · word · Me

ethereum dapp Embark Cockpit

https://embark.status.im/docs/cockpit_dashboard.html

2019-05-28 · 1 min · word · Me

truffle truffle-hdwallet-provider Error: Error: the tx doesn't have the correct nonce. account has nonce of: 3 tx has nonce of: 2

What this Error? Example: transaction A get nonce 1 transaction B get nonce 2 transaction C get nonce 3 But blockchain package B、C first, then package A. If happen this step, get error. With truffle? Because Normal const wallet = new HDWalletProvider(mnemonic, url, id); const AContract = new TruffleContract(Json_contract); AContract.setProvider(wallet); wallet.addresses[] AContract. use contract api Sometime you call contract “set/write” api two times. Example: Create contract first. Write data into contract second. This two step are in one function. This mean is you call two time “new HDWalletProvide”. Usually you think “New“ two time is ok, get “new” instance. But ...

2019-05-21 · 1 min · 134 words · Me

geth add peers static-nodes.json

https://medium.com/taipei-ethereum-meetup/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E7%A7%81%E7%B6%B2%E5%BB%BA%E7%AB%8B-%E4%B8%80-43f8677fc9f8 如果要組成一個私人網路,同樣按照上面的流程建立其他節點。如果沒有下–nodiscover參數的話,最後節點應該會找到彼此。如果有下的話就必須用手動的方式加入其他節點,加入的方式有三種: 一是在geth指令加入–bootnodes參數; 二是進到console裡使用 admin.addPeer(); 三是存成static-nodes.json檔,讓geth自動連線。 不管是使用哪一種,我們都要先知道要連到 static-nodes.json 裡面使用domain,可能會有問題,要自行更換ip Example: geth --data ~/data cp static-nodes.json ~/data/geth/static-nodes.json static-nodes.json like this [ "enode://53999cc519079c5190798b1114bd16a05a8d5190796cc51907988a4e80ebda7b6c519079e56b0b161da3475c4dc62f6b51907967a6e327e46aa56329c519079f@192.168.0.10:30303" ]

2019-04-24 · 1 min · 22 words · Me

geth 新版 豪秒產生無法匯入

geth新版的geth.log 會產生豪秒 舊 INFO [04-22|16:29:56] 新 INFO [03-28|13:43:35.004] 差別在.004 看log會發現只有logstash的warning,經同事正確解釋是: >>因為logstash轉換出來的日期格式2019-03-28 13:43:35.004,Elasticsearch不認得,所以對logstash來說是Warning,但對Elasticsearch是Error,造成Log寫不進去~ 所以在logstash.conf上必須在解析date上,補上 “YYYY-MM-dd HH:mm:ss,SSS”, “YYYY-MM-dd HH:mm:ss.SSS” date { match => \[ "gethdate" , "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss,SSS", "YYYY-MM-dd HH:mm:ss.SSS"\] target => "gethdate" timezone => "Asia/Taipei" } 這樣就可以正常匯入geth.log了

2019-04-23 · 1 min · 38 words · Me

ganache-cli geth test developer ethereum

ethereum ganache-cli https://github.com/trufflesuite/ganache-cli

2019-04-18 · 1 min · 3 words · Me

ethereum-etl to csv to filebeat to kafka to mysql

filbeat to kafka https://www.elastic.co/guide/en/beats/filebeat/current/kafka-output.html sink-connector to mysql https://docs.confluent.io/current/connect/kafka-connect-jdbc/sink-connector/index.html

2019-02-12 · 1 min · 8 words · Me

ethereum etl ELK docker docker-compose .env startblock endblock

ethereum-etl export data every time write over file. Filebeat always reload file then ELK receive repeat records… So .env STARTBLOCK=01205866 ENDBLOCK=01205888 startetl.sh IP_PORT is go-ethereum-node1 outside ip & port. here is docker-machine source get file that path need to be careful #!/bin/bash IP_PORT=192.168.99.100:18545 ETH_METHOD=eth_blockNumber BLOCKNUMBER_JSON_HEX=$(curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"'$ETH_METHOD'","params":[],"id":1}' $IP_PORT | jq '.result' | tr -d '"') BLOCKNUMBER_DEX=$(printf "%08d\n" $BLOCKNUMBER_JSON_HEX) printf "\n===== Now Geth BlockerNumber =====\n" printf "HEX: %s\n" $BLOCKNUMBER_JSON_HEX printf "DEC: %s\n" $BLOCKNUMBER_DEX source .env #source ~/ethereum_etl/.env printf "\n===== .env BLOCK VARS =====\n" printf "STARTBLOCK: %s\n" $STARTBLOCK printf "ENDBLOCK: %s\n" $ENDBLOCK if [[ $BLOCKNUMBER_DEX =~ ^?[0-9]+$ ]] || [ -z $BLOCKNUMBER_DEX ]; then printf "NOT Number Geth BLOCKNUMBER, check Geth\n" exit fi if [[ $STARTBLOCK =~ ^?[0-9]+$ ]] || [ -z $STARTBLOCK ]; then printf "NOT Number .env STARTBLOCK, check .env\n" exit fi if [[ $ENDBLOCK =~ ^?[0-9]+$ ]] || [ -z $ENDBLOCK ]; then printf "NOT Number .env ENDBLOCK, check .env\n" exit fi #printf "\n%s\n" $BLOCKNUMBER_DEX #printf "%s" $STARTBLOCK #printf "\n%s\n" $((10#$BLOCKNUMBER_DEX - 10#$STARTBLOCK)) if (( (( 10#$BLOCKNUMBER_DEX - 10#$STARTBLOCK -1 )) > 0 )); then printf "\n===== Change .env =====\n" printf "startblock: %s => %s\n" $STARTBLOCK $((10#$ENDBLOCK+1)) printf "endblock: %s => %s\n" $ENDBLOCK $BLOCKNUMBER_DEX STARTBLOCK=$(printf "%08d\n" $((10#$ENDBLOCK+1)) ) echo STARTBLOCK=$STARTBLOCK > ~/ethereum_etl/.env echo ENDBLOCK=$BLOCKNUMBER_DEX >> .env #echo STARTBLOCK=$STARTBLOCK > ~/ethereum_etl/.env #echo ENDBLOCK=$BLOCKNUMBER_DEX >> ~ethereum_etl/.env fi docker-compose up --build ethereum_etl docker-compose.yml version: '3.3' services: go-ethereum-node1: build: context: go-ethereum-node1/ volumes: #- ./go-ethereum/keystore:/root/.ethereum/devchain/keystore:rw - ./go-ethereum-node1/genesis/poa_for_dev.json:/root/genesis/poa_for_dev.json:ro - alldata:/root/.ethereum/devchain - /etc/localtime:/etc/localtime:ro #- ./go-ethereum/log:/root/log:rw entrypoint: /root/start.sh ports: - "18545:8545" - "30313:30303" - "30313:30303/udp" networks: - etl ethereum_etl: build: context: ethereum-etl/ env_file: .env volumes: - alldata:/ethereum-etl/output:rw #- /root/go/src/github.com/ethereum/go-ethereum/build/bin/data:/ethereum-etl/ipc #restart: unless-stopped networks: - etl volumes: alldata: networks: etl: driver: bridge ethereum_etl DOCKERFILE FROM python:3.6-alpine MAINTAINER Eric Lim ENV PROJECT_DIR=ethereum-etl RUN apk add unzip RUN wget https://github.com/blockchain-etl/ethereum-etl/archive/develop.zip \ && unzip develop.zip && rm develop.zip RUN mv ethereum-etl-develop /$PROJECT_DIR WORKDIR /$PROJECT_DIR RUN apk add --no-cache gcc musl-dev #for C libraries: RUN pip install --upgrade pip && pip install -e /$PROJECT_DIR/ #CMD ["export_all", "-s", "01990000", "-e", "99999999", "-p", "http://xxx.xxx.xxx.xxx:8545", "-o", "output"] #CMD ["sh","-c", "echo startblock=$STARTBLOCK endblock=$ENDBLOCK"] CMD ["sh","-c","python ethereumetl export_all -s $STARTBLOCK -e $ENDBLOCK -p http://xxx.xxx.xxx.xxx:8545 -o output"] go-ethereum-node1 see https://sueboy.blogspot.com/search?q=poa ...

2019-01-23 · 2 min · 356 words · Me

elasticsearch dump ethereum-etl

https://github.com/taskrabbit/elasticsearch-dump Output elasticsearch->json docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-logs --output=/tmp/etl-logs.json --type=mapping docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-transactions --output=/tmp/etl-transactions.json --type=mapping docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-receipts --output=/tmp/etl-receipts.json --type=mapping docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-contracts --output=/tmp/etl-contracts.json --type=mapping docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-blocks --output=/tmp/etl-blocks.json --type=mapping docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-logs --output=/tmp/etl-logs-data.json --type=data docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-transactions --output=/tmp/etl-transactions-data.json --type=data docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-receipts --output=/tmp/etl-receipts-data.json --type=data docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-contracts --output=/tmp/etl-contracts-data.json --type=data docker run --rm -ti -u root -v /mnt/sda1/var/lib/docker/volumes/xxxxxxx/_data/data:/tmp taskrabbit/elasticsearch-dump --input=http://192.168.99.101:9200/filebeat-6.5.4-etl-blocks --output=/tmp/etl-blocks-data.json --type=data Innput json->elasticsearch docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-contracts.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-contracts --type=mapping docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-contracts-data.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-contracts --type=data docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-receipts.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-receipts --type=mapping docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-receipts-data.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-receipts --type=data docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-transactions.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-transactions --type=mapping docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-transactions-data.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-transactions --type=data docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-blocks.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-blocks --type=mapping docker run --rm -ti -u root -v data:/tmp taskrabbit/elasticsearch-dump --input=/tmp/etl-blocks-data.json --output=http://xxx.xxx.xxx.xxx:9200/filebeat-6.5.4-etl-blocks --type=_data

2019-01-21 · 2 min · 221 words · Me

elk kibana search geth ethereum

https://blog.csdn.net/qq_38486203/article/details/80817037 Search minedNumber GET /filebeat-6.*-geth*/_search?q=geth_ip:xxx.xxx.xxx.xxx { "_source": ["name", "minedNumber", "gethdate"], "sort": [ { "gethdate": { "order": "desc" } } ], "from": 1, "size": 1 } Get minedNumber curl -XGET "http://xxx.xxx.xxx.xxx:9200/filebeat-6.*-geth*/_search?q=geth_ip:xxx.xxx.xxx.xxx" -H 'Content-Type: application/json' -d' { "_source": ["name", "minedNumber", "gethdate"], "sort": [ { "gethdate": { "order": "desc" } } ], "from": 1, "size": 1 }' | jq ".hits.hits[]._source.minedNumber"

2019-01-17 · 1 min · 57 words · Me

ethereum-etl ethereumetl docker part2 use .env

docker-compose.yml version: '3.3' services: ethereum_etl: build: context: . env_file: .env volumes: - /var/log/hardblue/etl/:/ethereum-etl/output:rw #- /root/go/src/github.com/ethereum/go-ethereum/build/bin/data:/ethereum-etl/ipc #restart: unless-stopped networks: - etl networks: etl: driver: bridge .env STARTBLOCK=00000000 DOCKERFILE FROM python:3.6-alpine MAINTAINER Eric Lim ENV PROJECT_DIR=ethereum-etl RUN apk add unzip RUN wget https://github.com/blockchain-etl/ethereum-etl/archive/develop.zip \ && unzip develop.zip && rm develop.zip RUN mv ethereum-etl-develop /$PROJECT_DIR WORKDIR /$PROJECT_DIR RUN apk add --no-cache gcc musl-dev #for C libraries: RUN pip install --upgrade pip && pip install -e /$PROJECT_DIR/ #CMD ["export_all", "-s", "01990000", "-e", "99999999", "-p", "http://xxx.xxx.xxx.xxx:8545", "-o", "output"] #CMD ["sh","-c", "echo startblock=$STARTBLOCK endblock=$ENDBLOCK"] CMD ["sh","-c","python ethereumetl export_all -s $STARTBLOCK -e $ENDBLOCK -p http://xxx.xxx.xxx.xxx:8545 -o output"] crontab -e ...

2019-01-17 · 1 min · 123 words · Me

Ethereum input data decoder

https://lab.miguelmota.com/ethereum-input-data-decoder/example/

2019-01-16 · 1 min · word · Me

ethereum-etl ethereumetl elk logstash kibana part2

filter { if [etltype] == "blocks" { #[fields][srctype] csv { columns => [ "number", "hash", "parent_hash", "nonce", "sha3_uncles", "logs_bloom", "transactions_root", "state_root", "receipts_root", "miner", "difficulty", "total_difficulty", "size", "extra_data", "gas_limit", "gas_used", "timestamp", "transaction_count" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } }else if [etltype] == "contracts" { #[fields][srctype] csv { columns => [ "address", "bytecode", "function_sighashes", "is_erc20", "is_erc721" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } }else if [etltype] == "logs" { #[fields][srctype] csv { columns => [ "log_index", "transaction_hash", "transaction_index", "block_hash", "block_number", "address", "data", "topics" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } }else if [etltype] == "receipts" { #[fields][srctype] csv { columns => [ "transaction_hash", "transaction_index", "block_hash", "block_number", "cumulative_gas_used", "gas_used", "contract_address", "root", "status" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } }else if [etltype] == "token_transfers" { #[fields][srctype] csv { columns => [ "" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } }else if [etltype] == "tokens" { #[fields][srctype] csv { columns => [ "" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } }else if [etltype] == "transactions" { #[fields][srctype] csv { columns => [ "hash", "nonce", "block_hash", "block_number", "transaction_index", "from_address", "to_address", "value", "gas", "gas_price", "inputcontext" ] separator => "," remove_field => ["message"] skip_empty_columns => true skip_empty_rows => true } } } output { if [etltype] == "blocks" { elasticsearch { hosts => "xxx.xxx.xxx.xxx:9200" manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-blocks-%{+YYYY.MM.dd}" document_id => "%{[hash]}" } }else if [etltype] == "logs" { elasticsearch { hosts => "xxx.xxx.xxx.xxx:9200" manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-logs-%{+YYYY.MM.dd}" } }else if [etltype] == "transactions" { elasticsearch { hosts => "xxx.xxx.xxx.xxx:9200" manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-transactions-%{+YYYY.MM.dd}" document_id => "%{[hash]}" } }else if [etltype] == "contracts" { elasticsearch { hosts => "xxx.xxx.xxx.xxx:9200" manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-contracts-%{+YYYY.MM.dd}" document_id => "%{[address]}" } }else{ elasticsearch { hosts => "xxx.xxx.xxx.xxx:9200" manage_template => false index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}" } } stdout { codec => rubydebug } } transactions csv fileds are ...

2019-01-14 · 2 min · 412 words · Me

get constract balance ethereum

https://ethereum.stackexchange.com/questions/21448/how-to-get-a-contracts-balance-in-solidity function contractbalance() public view returns (uint256){ return address(this).balance; } var thecontract = web3.eth.contract([{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"gett","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"buy","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Set","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"tokens","type":"uint256"}],"name":"Buyvalue","type":"event"}]); var MyContract = thecontract.at('0xbed0229199614a11e47c39d4800420de968627fa'); MyContract.buy({ from:'0x5921a4C1B13afbD4b61d63e9c7BD47741C47B176', value:web3.toWei("1", "ether") }, console.log)

2019-01-03 · 1 min · 24 words · Me

use remix ethereum online smart constract console Invalid JSON RPC response: undefined

Just try to click website function or action. Like compile, then try again console web3.eth.accounts maybe no error Or var web3 = new Web3(new Web3.providers.HttpProvider(“http://myLocalHostIP:myRpcPort”));

2019-01-03 · 1 min · 25 words · Me

ethereum smart contract payable

https://remix.ethereum.org/ Method 1: No function name function () payable external { t = msg.value; emit Buyvalue(msg.value); } function () payable external { OR function () external payable { pragma solidity >=0.4.0 <0.6.0; contract SimpleStorage { uint storedData; uint256 t; event Set(address indexed _from, uint value); event Buyvalue(uint tokens); function set(uint x) public { storedData = x; emit Set(msg.sender, x); } function get() public view returns (uint) { return storedData; } function gett() public view returns (uint) { return t; } function () payable external { t = msg.value; emit Buyvalue(msg.value); } } MetaMask can not director send contract address eth, so use console ...

2019-01-03 · 2 min · 263 words · Me

ethereum ERC20

https://www.ethereum.org/token https://theethereum.wiki/w/index.php/ERC20_Token_Standard https://github.com/bokkypoobah/Tokens#fixed-supply-token

2019-01-03 · 1 min · 3 words · Me