狼愛上貍

          我胡漢三又回來了

          #

          truffle里的solc版本與實(shí)際solc版本沖突的問題

          1.因?yàn)閟olc@0.5.1出現(xiàn)調(diào)用簡(jiǎn)單運(yùn)算合約出現(xiàn)返回0的問題,所以把solc降到了0.4.22。
          2.安裝truffle后,npm install -g truffle,版本有所不同:
          PS C:\> truffle version
          Truffle v5.0.24 (core: 5.0.24)
          Solidity v0.5.0 (solc-js)
          Node v10.16.0
          Web3.js v1.0.0-beta.37
          3.建立簡(jiǎn)單合約Greeter.sol后,利用truffle compile后,出現(xiàn):
          Error: CompileError: ParsedContract.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.8+commit.23d335f2.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
          pragma solidity ^0.4.24;
          ^----------------------^

          Compilation failed. See above.
          4.修改truffle-config.js文件:
          module.exports = {
          // Uncommenting the defaults below
          // provides for an easier quick-start with Ganache.
          // You can also follow this format for other networks;
          // see <http://truffleframework.com/docs/advanced/configuration>
          // for more details on how to specify configuration options!
          /*
          networks: {
          development: {
          host: "127.0.0.1",
          port: 7545,
          network_id: "*"
          },
          test: {
          host: "127.0.0.1",
          port: 7545,
          network_id: "*"
          }
          }
          */
          compilers: {
          solc: {
          version: "0.4.24"
          }
          }
          };
          5.再次編譯,出現(xiàn)
          /C/users/administrator/webstormprojects/testtruffle/contracts/Migrations.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.4.24+commit.e67f0147.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
          pragma solidity >=0.4.25 <0.6.0;
          ^------------------------------^
          6.打開Migrations.sol文件,
          把pragma solidity >=0.4.25 <0.6.0;
          修改為:pragma solidity >=0.4.24 <0.6.0;
          編譯通過。

          posted @ 2019-06-25 09:05 狼愛上貍 閱讀(2101) | 評(píng)論 (0)編輯 收藏

          ipfs + 以太坊實(shí)例解析

          本文章的項(xiàng)目基于春哥的博客教程
          【IPFS + 區(qū)塊鏈 系列】 入門篇 - IPFS + Ethereum (下篇)-ipfs + Ethereum 大圖片存儲(chǔ)

          我個(gè)人只是作為記錄學(xué)習(xí)心得所借鑒
          項(xiàng)目流程

          首先調(diào)用代碼創(chuàng)建truffle項(xiàng)目

              truffle unbox react

          其次,要引入ipfs的api,用作圖片存儲(chǔ)的相關(guān)功能,我們是將圖片存儲(chǔ)到ipfs當(dāng)中,而將所獲得圖片的hash區(qū)塊鏈之中,區(qū)塊鏈大數(shù)據(jù)成本的問題

              npm install –save ipfs-api

          安裝完畢調(diào)用complie編譯合約代碼,,以便使用web3調(diào)用合約存儲(chǔ)區(qū)塊鏈

              compile

          替換合約地址,這個(gè)需要將合約在以太坊部署并取得對(duì)應(yīng)地址
          然后運(yùn)行ipfs節(jié)點(diǎn)

              ipfs daemon

          啟動(dòng)項(xiàng)目

              npm start

          就可以看到項(xiàng)目成功
          代碼解讀分析

          import React, {Component} from 'react'
          import SimpleStorageContract from '../build/contracts/SimpleStorage.json'
          import getWeb3 from './utils/getWeb3'

          import './css/oswald.css'
          import './css/open-sans.css'
          import './css/pure-min.css'
          import './App.css'

          const ipfsAPI = require('ipfs-api');
          const ipfs = ipfsAPI({host: 'localhost', port: '5001', protocol: 'http'});

          const contract = require('truffle-contract')
          const simpleStorage = contract(SimpleStorageContract)
          let account;

          /** Declaring this for later so we can chain functions on SimpleStorage.**/
          let contractInstance;
          //ipfs保存圖片方法//
          let saveImageOnIpfs = (reader) => {
            return new Promise(function(resolve, reject) {
              const buffer = Buffer.from(reader.result);
              ipfs.add(buffer).then((response) => {
                console.log(response)
                resolve(response[0].hash);
              }).catch((err) => {
                console.error(err)
                reject(err);
              })
            })
          }

          //創(chuàng)建構(gòu)造函數(shù),添加狀態(tài)機(jī)變量//

          class App extends Component {
            constructor(props) {
              super(props)

              this.state = {
                blockChainHash: null,
                web3: null,
                address: null,
                imgHash: null,
                isWriteSuccess: false
              }
            }
          //程序啟動(dòng)默認(rèn)調(diào)用方法//
            componentWillMount() {
              //打印項(xiàng)目中網(wǎng)絡(luò)節(jié)點(diǎn)//
              ipfs.swarm.peers(function(err, res) {
                if (err) {
                  console.error(err);
                } else {
                  /** var numPeers = res.Peers === null ? 0 : res.Peers.length;**/
                  /** console.log("IPFS - connected to " + numPeers + " peers");**/
                  console.log(res);
                }
              });
              //web3設(shè)置,同時(shí)調(diào)用初始化方法//
              getWeb3.then(results => {
                this.setState({web3: results.web3})

                // Instantiate contract once web3 provided.
                this.instantiateContract()
              }).catch(() => {
                console.log('Error finding web3.')
              })
            }
              //初始化合約實(shí)例、web3獲取合約賬號(hào)以及合約實(shí)例//
            instantiateContract = () => {

              simpleStorage.setProvider(this.state.web3.currentProvider);
              this.state.web3.eth.getAccounts((error, accounts) => {
                account = accounts[0];
                simpleStorage.at('0xf6a7e96860f05f21ecb4eb588fe8a8a83981af03').then((contract) => {
                  console.log(contract.address);
                  contractInstance = contract;
                  this.setState({address: contractInstance.address});
                  return;
                });
              })

            }
            render() {
              return (<div className="App">
                {
                  this.state.address
                    ? <h1>合約地址:{this.state.address}</h1>
                    : <div/>
                }
                <h2>上傳圖片到IPFS:</h2>
                /**這一部分用于上傳文件到ipfs**/
                <div>
                  <label id="file">Choose file to upload</label>
                  <input type="file" ref="file" id="file" name="file" multiple="multiple"/>
                </div>
                <div>
                  <button onClick={() => {
                      var file = this.refs.file.files[0];
                      var reader = new FileReader();
                      // reader.readAsDataURL(file);
                      reader.readAsArrayBuffer(file)
                      reader.onloadend = function(e) {
                        console.log(reader);
                        saveImageOnIpfs(reader).then((hash) => {
                          console.log(hash);
                          this.setState({imgHash: hash})
                        });

                      }.bind(this);

                    }}>將圖片上傳到IPFS并返回圖片HASH</button>
                </div>
                 /**這一部分用于上傳hash到區(qū)塊鏈**/
                {
                  this.state.imgHash
                    ? <div>
                        <h2>imgHash:{this.state.imgHash}</h2>
                        <button onClick={() => {
                            contractInstance.set(this.state.imgHash, {from: account}).then(() => {
                              console.log('圖片的hash已經(jīng)寫入到區(qū)塊鏈!');
                              this.setState({isWriteSuccess: true});
                            })
                          }}>將圖片hash寫到區(qū)塊鏈:contractInstance.set(imgHash)</button>
                      </div>
                    : <div/>
                }
                {
                  this.state.isWriteSuccess
                    ? <div>
                        <h1>圖片的hash已經(jīng)寫入到區(qū)塊鏈!</h1>
                        <button onClick={() => {
                            contractInstance.get({from: account}).then((data) => {
                              console.log(data);
                              this.setState({blockChainHash: data});
                            })
                          }}>從區(qū)塊鏈讀取圖片hash:contractInstance.get()</button>
                      </div>
                    : <div/>
                }
                {
                  this.state.blockChainHash
                    ? <div>
                        <h3>從區(qū)塊鏈讀取到的hash值:{this.state.blockChainHash}</h3>
                      </div>
                    : <div/>
                }
                {
                  this.state.blockChainHash
                    ? <div>
                        <h2>瀏覽器訪問:{"http://localhost:8080/ipfs/" + this.state.imgHash}</h2>
                        <img alt="" style={{width:200}} src={"http://localhost:8080/ipfs/" + this.state.imgHash}/>
                      </div>
                    : <img alt=""/>
                }
              </div>);
            }
          }

          export default App



          該項(xiàng)目算是truffle和ipfs結(jié)合以太坊一起使用的綜合案例,用與梳理知識(shí)點(diǎn)
          ---------------------
          作者:czZ__czZ
          來源:CSDN
          原文:https://blog.csdn.net/czZ__czZ/article/details/79036567
          版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!

          posted @ 2019-06-25 08:21 狼愛上貍 閱讀(338) | 評(píng)論 (0)編輯 收藏

          nodejs-執(zhí)行報(bào)錯(cuò)Error: Cannot find module 'express'

          1. C:\Users\0>node E:\項(xiàng)目\2018年\11月份\nodejs\express_demo.js
          2. module.js:471
          3. throw err;
          4. ^
          5. Error: Cannot find module 'express'
          6. at Function.Module._resolveFilename (module.js:469:15)
          7. at Function.Module._load (module.js:417:25)
          8. at Module.require (module.js:497:17)
          9. at require (internal/module.js:20:19)
          10. at Object.<anonymous> (E:\項(xiàng)目\2018年\11月份\nodejs\express_demo.js:1:77)
          11. at Module._compile (module.js:570:32)
          12. at Object.Module._extensions..js (module.js:579:10)
          13. at Module.load (module.js:487:32)
          14. at tryModuleLoad (module.js:446:12)
          15. at Function.Module._load (module.js:438:3)
          16. C:\Users\0>express --version
          17. 4.16.0

          實(shí)際上我是有安裝express模塊的

          奇了個(gè)怪了。

          然后試過1種方法是進(jìn)入項(xiàng)目目錄再執(zhí)行安裝express模塊,無效

          最后,原來是node_modules沒有配置環(huán)境變量

          配置上吧:

          1、控制面板\所有控制面板項(xiàng)\系統(tǒng)\高級(jí)系統(tǒng)設(shè)置\環(huán)境變量

          新建設(shè)‘NODE_PATH’:C:\Users\0\AppData\Roaming\npm\node_modules

           編輯增加環(huán)境變量‘PATH’

          完美~~


          http://www.pianshen.com/article/837378161/


          posted @ 2019-06-23 22:31 狼愛上貍 閱讀(1596) | 評(píng)論 (0)編輯 收藏

          調(diào)用智能合約簡(jiǎn)單運(yùn)算總返回0的問題

          1.合約內(nèi)容
          pragma
          solidity ^0.5.9;

          contract hello {

          function mutiply(uint a) public pure returns (uint result) {

          return a*3;

          }
          }
          2.部署合約:
          var Web3 = require("web3");
          var fs = require("fs");
          var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
          var code = '0x' + fs.readFileSync("2_sol_hello.bin").toString();
          var abi = JSON.parse(fs.readFileSync("2_sol_hello.abi").toString());
          var contract = web3.eth.contract(abi);
          console.log(web3.eth.accounts);
          console.log('account balance:' + web3.eth.getBalance(web3.eth.accounts[0]))

          web3.personal.unlockAccount(web3.eth.accounts[0],"123")
          var contract = contract.new({from: web3.eth.accounts[0], data: code, gas: 470000},
          function(e, contract){

          if(!contract.address) {
          console.log("已經(jīng)發(fā)起交易,交易地址:" + contract.transactionHash + "\n正在等待挖礦");
          } else {
          console.log("智能合約部署成功,地址:" + contract.address);

          }

          }
          )
          3.調(diào)用合約
          var Web3 = require("web3");
          var fs = require("fs");
          var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
          var abi = JSON.parse(fs.readFileSync("2_sol_hello.abi").toString());
          var contract = web3.eth.contract(abi);
          var instance = contract.at('0xb06846c54c6ae67102ed67ce57a357a643d1f1b8')
          web3.personal.unlockAccount(web3.eth.accounts[0],"123")
          console.log(instance.mutiply(12).toString())
          4.顯示結(jié)果為:
          0
          原因:solc版本0.5.9太高,可能調(diào)用的方法不對(duì)。
          解決方法:npm install -g solc@0.4.22
          降低版本,然后把合約第一行改為:
          pragma solidity ^0.4.22;
          問題解決。

          posted @ 2019-06-23 18:12 狼愛上貍 閱讀(302) | 評(píng)論 (0)編輯 收藏

          以太坊(二)MAC搭建以太坊私有鏈多節(jié)點(diǎn)集群(同一臺(tái)電腦)

          https://www.jianshu.com/p/52e9588116ad

          posted @ 2019-06-20 14:47 狼愛上貍 閱讀(234) | 評(píng)論 (0)編輯 收藏

          web3.php Error: The method personal_newAccount does not exist/is not available

          很多人遇到這個(gè)問題:

          web3.php Error: The method personal_newAccount does not exist/is not available。

          其實(shí)很簡(jiǎn)單,我們只需要在geth啟動(dòng)時(shí)的rpc參數(shù)中設(shè)置rpcapi時(shí)包括 "personal" 即可。

          geth --rpc --rpcaddr 0.0.0.0 --rpcport 8545 --rpcapi eth,web3,admin,personal,net


          來自:http://www.bcfans.com/toutiao/redian/101819.html


          我的是:
          geth --identity "Water" --rpc --rpcport "8080" --rpccorsdomain "*" --datadir gethdata --port "30303" --nodiscover --rpcapi "db,eth,net,personal,web3" --networkid 1999 init genesis.json

          posted @ 2019-06-19 10:42 狼愛上貍 閱讀(568) | 評(píng)論 (0)編輯 收藏

          windows安裝web3

          1.安裝web3要先安裝node。
          2.cmd->powershell
          3.c:\>node
            >require('web3')
          結(jié)果輸出一些錯(cuò)誤,表明還沒安裝web3。
          4.c:\>npm install web3
          5.安裝后,再
           c:\>node
            >require('web3')
          輸出
          [Function:Web3]
          表明web3就安裝好了。

          posted @ 2019-06-17 14:26 狼愛上貍 閱讀(850) | 評(píng)論 (1)編輯 收藏

          本地自動(dòng)化編譯、部署和調(diào)用智能合約

          https://blog.csdn.net/qiubingcsdn/article/details/89703128

          posted @ 2019-06-15 23:05 狼愛上貍 閱讀(245) | 評(píng)論 (0)編輯 收藏

          本地搭建以太坊私有網(wǎng)絡(luò)-基于Ganache和MetaMask

              背景介紹

          本文主要介紹如何使用Ganache,在本地搭建以太坊私有網(wǎng)絡(luò),并進(jìn)行簡(jiǎn)單的測(cè)試。

           

              所需軟件

                Ganache

          Ganache用于搭建私有網(wǎng)絡(luò)。在開發(fā)和測(cè)試環(huán)境下,Ganache提供了非常簡(jiǎn)便的以太坊私有網(wǎng)絡(luò)搭建方法,通過可視化界面可以直觀地設(shè)置各種參數(shù)、瀏覽查看賬戶和交易等數(shù)據(jù)。

          下載地址為:https://truffleframework.com/ganache/

                  MetaMask

          MetaMask用于測(cè)試私有網(wǎng)絡(luò)。MetaMask是一個(gè)輕量級(jí)的以太坊錢包,由于它是一個(gè)Chrome插件,因此使用MetaMask可以非常方便地在瀏覽器中完成以太坊轉(zhuǎn)賬等操作。

          下載地址為:https://www.metamask.io

           

              操作步驟

               安裝、啟動(dòng)Ganache

          1. 使用安裝包安裝即可。

          2. 打開程序后,會(huì)顯示以下界面,用戶可以查看賬戶(默認(rèn)創(chuàng)建10個(gè)賬戶)、區(qū)塊、交易和日志。

           

          3. 點(diǎn)擊“設(shè)置”,如下圖所示,用戶還可以設(shè)置綁定的ip和端口(設(shè)置為8545即可,稍后MetaMask會(huì)用這個(gè)端口)、賬戶數(shù)量以及gas限制等,點(diǎn)擊“restart”后設(shè)置生效。

           

          此時(shí),Ganache已經(jīng)在本機(jī)運(yùn)行了一個(gè)以太坊私有網(wǎng)絡(luò),并綁定了8545端口。

           

              安裝、啟動(dòng)MetaMask

          1. 把插件添加到chrome擴(kuò)展程序即可

          2. 點(diǎn)擊Chrome中的MetaMask圖標(biāo),按照每一步提示啟動(dòng)MetaMask

          3. 如下圖所示,設(shè)置MetaMask連接到本地的以太坊私有網(wǎng)絡(luò)

              

          此時(shí),MetaMask就可以和本地的以太坊私有網(wǎng)絡(luò)進(jìn)行交互了。

           

              用MetaMask測(cè)試私有網(wǎng)絡(luò)

          1. 從Ganache創(chuàng)建的賬戶中選擇一個(gè)導(dǎo)入到MetaMask中

              a. 在Ganache賬戶頁面選定一個(gè)賬戶,點(diǎn)擊最右邊的小鑰匙圖標(biāo),復(fù)制其私鑰(private key)

              b. 在MetaMask中點(diǎn)擊頭像,選擇 “import account”,彈出對(duì)話框

              c.  把復(fù)制的賬戶私鑰填入文本框中,并點(diǎn)擊“import”

           

          此時(shí),MetaMask就可以操作這個(gè)新賬戶了。

           

          2. 用新導(dǎo)入的賬戶進(jìn)行轉(zhuǎn)賬

              a. 點(diǎn)擊“send”按鈕,彈出轉(zhuǎn)賬對(duì)話框

              b. 從Ganache賬戶頁面中,再選定一個(gè)其他的賬戶,復(fù)制其地址

              c. 把復(fù)制的地址填入到 “to” 文本框中,并在“amount”文本框中填入一個(gè)數(shù)值,表示要轉(zhuǎn)賬的金額(如 “10”);其它文本框默認(rèn)值即可

              d. 點(diǎn)擊next,彈出轉(zhuǎn)賬確認(rèn)框,點(diǎn)擊“confirm”確認(rèn)交易

              e. 提醒轉(zhuǎn)賬成功后,可以看到賬戶余額發(fā)生了變化,此時(shí)再轉(zhuǎn)到Ganache賬戶頁面,也可看到兩個(gè)賬戶的余額也都發(fā)生了變化。

           

              注意

          由于Ganache的交易數(shù)據(jù)是在內(nèi)存中操作的,并沒有持久化到本地硬盤中,因此每次Ganache重啟后,其上一次的交易記錄就沒有了,都是重新開始的。重啟Ganache后,再在MetaMask中轉(zhuǎn)賬就會(huì)發(fā)生錯(cuò)誤,解決辦法是在MetaMask設(shè)置中“restart account”,然后再操作就ok了。

          如果想保留Ganache每一次運(yùn)行時(shí)的交易數(shù)據(jù),以便下一次繼續(xù)使用,可以使用命令行的形式ganache-cli啟動(dòng)Ganache,并指定數(shù)據(jù)存儲(chǔ)目錄
          ---------------------
          作者:BigCuttie
          來源:CSDN
          原文:https://blog.csdn.net/starleelzx/article/details/82943530
          版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!

          posted @ 2019-06-13 22:51 狼愛上貍 閱讀(1070) | 評(píng)論 (0)編輯 收藏

          webstrom下載安裝

          1.https://www.jetbrains.com/webstorm/download/ 下載2019.1.3版

          2.在網(wǎng)盤開發(fā)軟件下載JetbrainsCrack3.4.jar、漢化包和激活碼軟件。
          3.將解壓的.jar 破解補(bǔ)丁放在你的安裝idea下面的bin的目錄下面。如C:\JetBrains\WebStorm\bin
          4.在安裝的idea下面的bin目錄下面有2個(gè)文件 : 一個(gè)是webstorm.exe.vmoptions,還有一個(gè)是webstorm64.exe.vmoptions。用記事本打開 分別在最下面一行增加一行:
          -javaagent:C:\JetBrains\WebStorm\bin\JetbrainsCrack3.4.jar
          5.重啟一下軟件,在進(jìn)入出現(xiàn)有active code選擇界面的時(shí)候,打開激活碼.txt文件,輸入即可,能夠進(jìn)入應(yīng)用界面則表示安裝破解成功

          posted @ 2019-06-11 10:04 狼愛上貍 閱讀(130) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共38頁: First 上一頁 5 6 7 8 9 10 11 12 13 下一頁 Last 
          主站蜘蛛池模板: 鹤岗市| 朝阳区| 太康县| 星座| 洪湖市| 将乐县| 吉首市| 大悟县| 永德县| 隆化县| 新巴尔虎右旗| 陈巴尔虎旗| 双牌县| 姜堰市| 屯留县| 莲花县| 承德县| 晋宁县| 永安市| 松原市| 花莲县| 诸暨市| 镇坪县| 新乡市| 杨浦区| 万宁市| 阿拉善左旗| 三江| 常熟市| 驻马店市| 都安| 阿巴嘎旗| 安仁县| 广元市| 镇康县| 疏附县| 清涧县| 大厂| 崇信县| 兴海县| 城固县|