web3 deploy smart contract 1.2.1

Use https://remix.ethereum.org Get Contract json and data. In remix website, Compile finish. See Compliation Details. 1. ABI: click ABI buttion, get data. Use http://jsonviewer.stack.hu/ remove space 2. Compliation Details -> WEB3DEPLOY -> get data 3. cContract.options.from need put correct. var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://ganache:8545"); var web3 = new Web3(provider); //abi var cContract = new 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"}]) //bytecode cContract.options.data = '0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b18114604d5780636d4ce63c146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b506076608d565b60408051918252519081900360200190f35b600055565b600054905600a165627a7a72305820765480c908e5e28e3233e18bfa422944b42cad5fc08b77d7b22d3ddd7016a1380029' cContract.options.from = '0xoooxxxoooxxxoooxxxoooxxxoooxxx' cContract.options.gas = '4700000' console.log("web3 version: %o", web3.version) web3.eth.getAccounts().then(o=>{console.log(o)}) cContract.deploy().send() .on('error', (error) => { console.log("error: %o", error) }) .on('transactionHash', (transactionHash) => { console.log("transactionHash: %o", transactionHash) }) .on('receipt', (receipt) => { // receipt will contain deployed contract address console.log("receipt: %o", receipt) console.log("receipt.contractAddress: %o", receipt.contractAddress) }) .on('confirmation', (confirmationNumber, receipt) => { console.log("confirmationNumber: %o", confirmationNumber) console.log("confirmation receipt: %o", receipt) }) .then(function(newContractInstance){ if (typeof newContractInstance.options.address !== 'undefined') { console.log('Contract mined! address: ' + newContractInstance.options.address); }else{ console.log("newContractInstance.address is undefined!") } });

2019-09-26 · 1 min · 141 words · Me

HDWalletProvider web3 smart contract connection need to stop or pool

HDWalletProvider engine.stop() p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0); p.engine.stop(); HDWalletProvider engine.stop() and pool export function GetHdProvider(id: number, rpcurl: string) { //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id); return id==0?Provider1Pool.acquire():Provider2Pool.acquire(); } // Normal use const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); // Normal release ReleaseHDProvider1(hdProvider1 ); // Pool code const genericPool = require("generic-pool"); const opts = { max: 10, // maximum size of the pool min: 2, // minimum size of the pool idleTimeoutMillis: 30000, log: true }; const factory0 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0); }, destroy: function(client) { client.engine.stop(); } }; const factory1 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 1); }, destroy: function(client) { client.engine.stop(); } }; export function ReleaseHDProvider1(client){ Provider1Pool.release(client); console.log("Provider1Pool status: pool.size %o pool.available %o pool.pending %o", Provider1Pool.size, Provider1Pool.available, Provider1Pool.pending) } export function ReleaseHDProvider2(client){ Provider2Pool.release(client); console.log("Provider2Pool status: pool.size %o pool.available %o pool.pending %o", Provider2Pool.size, Provider2Pool.available, Provider2Pool.pending) } const Provider1Pool = genericPool.createPool(factory0, opts); const Provider2Pool = genericPool.createPool(factory1, opts);

2019-09-25 · 1 min · 179 words · Me

Project專案

‎Triton Ho‎ https://www.facebook.com/groups/616369245163622/permalink/1736421439825058/ 今天不寫發大財的事,直接寫一下project planning的雜感好了。 —————————————————————————————————————————————————————— 最兇險的專案不是那些deadline定得很趕的專案,而是那些沒有deadline的專案! 別以為「沒有deadline」是真的沒有deadline耶。 你想一下,跟你大大聲說「錢不是問題的人」,最終有120%是「反正我又沒錢,錢當然不是問題啊~」。 公司不是做慈善的,也不是給工程師來試新玩具的。所有的專案,最終還是要談C/P值。 (再次一句:工程就是來談C/P的,不談C/P請去當藝術家) 所謂「沒有deadline」,這很可能代表…… A) 你的主管現在忙別的專案管理,暫時沒空管這專案。 (然後等他有空回來看這專案時,就會問為何拖這麼久還結不了案了) B) 你沒法拒絕其他人的需求改動。(背景聲:反正沒deadline,改一下需求去做得更好吧) C) 你沒法有效限制專案的複雜性,大量的over-engineering。(背景聲:反正沒deadline,寫得好一點/多留一點空間,這樣子未來才容易維護嘛) A+B+C的後果是……老闆過了三個月,突然有空來看看大家做什麼時,發現這專案已經過了二個月還沒有做完。 然後要求:都做了三個月了,現在再給你二星期時間來結案耶! 結果是: 要麼結不了案,投入大量心力的專案成為上不了市場的垃圾。 要麼是勉強能結案,但是有大量的over-engineering和一堆因為需求改了又改下不好的程式加構。 —————————————————————————————————————————————————————— 雖然一堆入市未深的工程師整天會罵專案deadline為何定得那麼硬,一天都不能改…… 但是嘛,先不談專案,我們談一下去旅行好了。 去旅行嘛,第一件事當然是跟公司申請休假,然後把信用卡丟給另一半叫她幫忙規劃(註:這是高度危險動作,好孩子絕對別學)。 http://xn--axxxx-fg1h292av9ap80aa49or2n76lzmxyz1bcr7i.com/,sxxxxxxxxx.com,txxxxxxxxxx.com上天天比價比優惠看旅行遊記的生活~ 然後如果沒定下死線?應該我進棺材那一天還是在計劃行程中~ (謎之聲:某人站在你身後,她看起來很火……) 計劃行程的死線能不能改?當然不行,公司休假可是改不動啊!!! 回到公司專案,為何公司死線定得那麼硬,很多時候都是跟業務宣傳/合約罰款有關的。 你想像一下,一個手游專案要上市,當然不是先等程式完成後才慢慢宣傳衝人氣的。 一個遊戲要上市,當然是先定好上市日期,然後預先數月就要慢慢地製造話題,找人來做宣傳,一步一步炒熱氣氛。 然後人氣炒到最高點,玩家的期待度到達最大時,遊戲同步開賣大賺特賺那一波。 如果突然發現有bug,遊戲要延期一個月? sorry囉,遊戲消費是不理性的,過了那一波熱潮,本來會付錢的玩家們早就付給另一個遊戲了。 讓話題多炒熱一個月去等bug先修好? 你以為是炒青菜,你想炒多久就多久嗎? 先不談熱度能否額外維持一個月還不消散。但是,高人流的宣傳管道,網上KOL,不是你想付錢就能立即買到的! 如果你沒法如期把遊戲上市,那麼你這個遊戲很可能就賠本賠很很大囉。 —————————————————————————————————————————————————————— 專案deadline不能改,商業社會就是這樣子了。 追求要完美的,你應該去當藝術家不是當工程師的。 怎去在deadline前做完專案,固然跟你是否有留下足夠的buffering有關。 但是,這跟你的專案怎計劃也有很大關係的。 上古時期,有一堆人(CMMI)覺得,只要把文件寫得好,每一個專案把工序所用的時間都記錄下來。 然後你就能越來越變得成熟,能很精準地預估下一個專案所需時間了~ 然後這些CMMI人大約會覺得:把台北的象山步道走100次,就能很精準地預估爬玉山攻項要多少時間了(笑~) (香港版本:走城門水塘100次,就能預估蚺蛇尖攻項要多少時間了) 會行山的人都知道: 地圖/網上文章只能給你一個很基本的大概,一個路線最終要用多少時間/體力,你只能親自走一次才能答出來。 然後嘛…… 很多表面上看起來相同的軟體專案,真正做下去時才發現是全新的未知領域…… —————————————————————————————————————————————————————— 如果專案deadline不能改,那麼能改的就是:軟件的質素了。 以去旅行為例: 如果你有非常充份的時間,你買機票時大可以找不同銀行的信用卡優惠,看看飛行里數計劃,看看連同旅行一起訂的優惠…… 如果沒時間,http://xn–skyxxxxxxx-rl5q.com/,輸入出發和回程時間,那一家最便宜就按下去算了。 一個能賣錢的軟體專案,正常應該可以再拆分為多個sub-task和milestone的。 重點: 首先開始做的,應該是最困難/你最沒法預估開發難度的工作。 A) 專案越早階段要改動上市日期,你能成功改動宣傳計劃的可能性就越高。 B) 越早發現專案進度不理想。之後比較容易的sub-task,你還是能以減少testcase coverage,刪掉不重要功能這些手段去追回進度。 如果你把困難而且必要的工作放在最後才做,那麼任何的預估錯誤就是專案延期囉~ (註1:一堆人覺得堅持一定要先寫testcase才能寫程式的……要麼他真的很幸福沒遇上過要衝死線的專案,要麼他活在童話世界……) (註2:deadline前做不完的軟體功能嘛……如果不是關鍵性的,看看能不能當成bug再後補囉~) ...

2019-09-19 · 1 min · 86 words · Me

pve lxc docker

https://www.pigo.idv.tw/archives/3322

2019-09-17 · 1 min · word · Me

HEX 0x string to []byte to string DecodeString

https://play.golang.org/p/i90_qsN2Sz- package main import ( "fmt" "encoding/hex" ) func main() { id := "0x1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c3519" fmt.Printf("Ori ID: %v \n\n", id) fmt.Printf("Ori ID[2:]: %v \n\n", id[2:]) byteid := []byte(id) fmt.Printf("===== Byte id ===== Decimal \n") fmt.Printf("Byte ID: %v \n", byteid) fmt.Printf("Byte ID 0x%x \n\n", byteid) fmt.Printf("===== Decode(Byte id[2:]) ===== Decimal HEX \n") byteid = []byte(id[2:]) fmt.Printf("Byte ID: %v \n", byteid) fmt.Printf("Byte ID 0x%x \n\n", byteid) n, _ := hex.Decode(byteid, byteid) fmt.Printf("Byte ID[2:]: %v \n", byteid) fmt.Printf("Byte ID[2:] 0x%x \n", byteid) fmt.Printf("Byte ID[2:] [:n]: %v \n", byteid[:n]) fmt.Printf("Byte ID[2:] [:n] 0x%x \n\n", byteid[:n]) fmt.Printf("===== id ===== Decimal \n") idbyte32 := covertStringTByte32(id) fmt.Printf("Byte32 ID: %v \n", idbyte32 ) //fmt.Printf("String ID: %s \n", idbyte32 ) fmt.Printf("HEX ID: 0x%x \n\n", idbyte32 ) fmt.Printf("===== id[2:] ===== Decimal \n") idbyte32 = covertStringT2Byte32(id) fmt.Printf("Byte32 ID: %v \n", idbyte32 ) //fmt.Printf("String ID: %s \n", idbyte32 ) fmt.Printf("HEX ID: 0x%x \n\n", idbyte32 ) fmt.Printf("===== DecodeString(id[2:]) ===== HEX \n") idbyte32 = covertStringDecodeStringByte32(id) fmt.Printf("Byte32 ID: %v \n", idbyte32 ) //fmt.Printf("String ID: %s \n", idbyte32 ) fmt.Printf("HEX ID: 0x%x \n", idbyte32 ) } func covertStringTByte32(t string) [32]byte { var b32 [32]byte copy(b32[:], t) return b32 } func covertStringT2Byte32(t string) [32]byte { var b32 [32]byte copy(b32[:], t[2:]) //remove 0x return b32 } func covertStringDecodeStringByte32(t string) [32]byte { data, err := hex.DecodeString(t[2:]) if err != nil { fmt.Printf("ERR \n") } fmt.Printf("DecodeString data: %v \n", data) fmt.Printf("DecodeString data length: %v \n\n", len(data)) var b32 [32]byte copy(b32[:], data) return b32 } Ori ID: 0x1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c3519 Ori ID[2:]: 1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c3519 ===== Byte id ===== Decimal Byte ID: [48 120 49 100 100 56 52 53 54 57 97 100 54 48 102 97 97 49 98 54 56 51 56 53 50 54 98 97 55 49 53 54 51 56 56 99 102 55 99 56 100 51 55 54 101 100 48 99 99 100 97 57 98 99 101 48 52 49 57 99 50 99 51 53 49 57] Byte ID 0x307831646438343536396164363066616131623638333835323662613731353633383863663763386433373665643063636461396263653034313963326333353139 ===== Decode(Byte id[2:]) ===== Decimal HEX Byte ID: [49 100 100 56 52 53 54 57 97 100 54 48 102 97 97 49 98 54 56 51 56 53 50 54 98 97 55 49 53 54 51 56 56 99 102 55 99 56 100 51 55 54 101 100 48 99 99 100 97 57 98 99 101 48 52 49 57 99 50 99 51 53 49 57] Byte ID 0x31646438343536396164363066616131623638333835323662613731353633383863663763386433373665643063636461396263653034313963326333353139 Byte ID[2:]: [29 216 69 105 173 96 250 161 182 131 133 38 186 113 86 56 140 247 200 211 118 237 12 205 169 188 224 65 156 44 53 25 56 99 102 55 99 56 100 51 55 54 101 100 48 99 99 100 97 57 98 99 101 48 52 49 57 99 50 99 51 53 49 57] Byte ID[2:] 0x1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c35193863663763386433373665643063636461396263653034313963326333353139 Byte ID[2:] [:n]: [29 216 69 105 173 96 250 161 182 131 133 38 186 113 86 56 140 247 200 211 118 237 12 205 169 188 224 65 156 44 53 25] Byte ID[2:] [:n] 0x1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c3519 ===== id ===== Decimal Byte32 ID: [48 120 49 100 100 56 52 53 54 57 97 100 54 48 102 97 97 49 98 54 56 51 56 53 50 54 98 97 55 49 53 54] HEX ID: 0x3078316464383435363961643630666161316236383338353236626137313536 ===== id[2:] ===== Decimal Byte32 ID: [49 100 100 56 52 53 54 57 97 100 54 48 102 97 97 49 98 54 56 51 56 53 50 54 98 97 55 49 53 54 51 56] HEX ID: 0x3164643834353639616436306661613162363833383532366261373135363338 ===== DecodeString(id[2:]) ===== HEX DecodeString data: [29 216 69 105 173 96 250 161 182 131 133 38 186 113 86 56 140 247 200 211 118 237 12 205 169 188 224 65 156 44 53 25] DecodeString data length: 32 Byte32 ID: [29 216 69 105 173 96 250 161 182 131 133 38 186 113 86 56 140 247 200 211 118 237 12 205 169 188 224 65 156 44 53 25] HEX ID: 0x1dd84569ad60faa1b6838526ba7156388cf7c8d376ed0ccda9bce0419c2c3519 Program exited. https://onlineutf8tools.com/convert-hexadecimal-to-utf8 ...

2019-09-11 · 4 min · 662 words · Me