<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    狼愛上貍

    我胡漢三又回來了

    #

    truffle里的solc版本與實際solc版本沖突的問題

    1.因為solc@0.5.1出現調用簡單運算合約出現返回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.建立簡單合約Greeter.sol后,利用truffle compile后,出現:
    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.再次編譯,出現
    /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 狼愛上貍 閱讀(2094) | 評論 (0)編輯 收藏

    ipfs + 以太坊實例解析

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

    我個人只是作為記錄學習心得所借鑒
    項目流程

    首先調用代碼創建truffle項目

        truffle unbox react

    其次,要引入ipfs的api,用作圖片存儲的相關功能,我們是將圖片存儲到ipfs當中,而將所獲得圖片的hash區塊鏈之中,區塊鏈大數據成本的問題

        npm install –save ipfs-api

    安裝完畢調用complie編譯合約代碼,,以便使用web3調用合約存儲區塊鏈

        compile

    替換合約地址,這個需要將合約在以太坊部署并取得對應地址
    然后運行ipfs節點

        ipfs daemon

    啟動項目

        npm start

    就可以看到項目成功
    代碼解讀分析

    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);
        })
      })
    }

    //創建構造函數,添加狀態機變量//

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

        this.state = {
          blockChainHash: null,
          web3: null,
          address: null,
          imgHash: null,
          isWriteSuccess: false
        }
      }
    //程序啟動默認調用方法//
      componentWillMount() {
        //打印項目中網絡節點//
        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設置,同時調用初始化方法//
        getWeb3.then(results => {
          this.setState({web3: results.web3})

          // Instantiate contract once web3 provided.
          this.instantiateContract()
        }).catch(() => {
          console.log('Error finding web3.')
        })
      }
        //初始化合約實例、web3獲取合約賬號以及合約實例//
      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到區塊鏈**/
          {
            this.state.imgHash
              ? <div>
                  <h2>imgHash:{this.state.imgHash}</h2>
                  <button onClick={() => {
                      contractInstance.set(this.state.imgHash, {from: account}).then(() => {
                        console.log('圖片的hash已經寫入到區塊鏈!');
                        this.setState({isWriteSuccess: true});
                      })
                    }}>將圖片hash寫到區塊鏈:contractInstance.set(imgHash)</button>
                </div>
              : <div/>
          }
          {
            this.state.isWriteSuccess
              ? <div>
                  <h1>圖片的hash已經寫入到區塊鏈!</h1>
                  <button onClick={() => {
                      contractInstance.get({from: account}).then((data) => {
                        console.log(data);
                        this.setState({blockChainHash: data});
                      })
                    }}>從區塊鏈讀取圖片hash:contractInstance.get()</button>
                </div>
              : <div/>
          }
          {
            this.state.blockChainHash
              ? <div>
                  <h3>從區塊鏈讀取到的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



    該項目算是truffle和ipfs結合以太坊一起使用的綜合案例,用與梳理知識點
    ---------------------
    作者:czZ__czZ
    來源:CSDN
    原文:https://blog.csdn.net/czZ__czZ/article/details/79036567
    版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

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

    nodejs-執行報錯Error: Cannot find module 'express'

    1. C:\Users\0>node E:\項目\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:\項目\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

    實際上我是有安裝express模塊的

    奇了個怪了。

    然后試過1種方法是進入項目目錄再執行安裝express模塊,無效

    最后,原來是node_modules沒有配置環境變量

    配置上吧:

    1、控制面板\所有控制面板項\系統\高級系統設置\環境變量

    新建設‘NODE_PATH’:C:\Users\0\AppData\Roaming\npm\node_modules

     編輯增加環境變量‘PATH’

    完美~~


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


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

    調用智能合約簡單運算總返回0的問題

    1.合約內容
    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("已經發起交易,交易地址:" + contract.transactionHash + "\n正在等待挖礦");
    } else {
    console.log("智能合約部署成功,地址:" + contract.address);

    }

    }
    )
    3.調用合約
    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.顯示結果為:
    0
    原因:solc版本0.5.9太高,可能調用的方法不對。
    解決方法:npm install -g solc@0.4.22
    降低版本,然后把合約第一行改為:
    pragma solidity ^0.4.22;
    問題解決。

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

    以太坊(二)MAC搭建以太坊私有鏈多節點集群(同一臺電腦)

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

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

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

    很多人遇到這個問題:

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

    其實很簡單,我們只需要在geth啟動時的rpc參數中設置rpcapi時包括 "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 狼愛上貍 閱讀(564) | 評論 (0)編輯 收藏

    windows安裝web3

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

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

    本地自動化編譯、部署和調用智能合約

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

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

    本地搭建以太坊私有網絡-基于Ganache和MetaMask

        背景介紹

    本文主要介紹如何使用Ganache,在本地搭建以太坊私有網絡,并進行簡單的測試。

     

        所需軟件

          Ganache

    Ganache用于搭建私有網絡。在開發和測試環境下,Ganache提供了非常簡便的以太坊私有網絡搭建方法,通過可視化界面可以直觀地設置各種參數、瀏覽查看賬戶和交易等數據。

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

            MetaMask

    MetaMask用于測試私有網絡。MetaMask是一個輕量級的以太坊錢包,由于它是一個Chrome插件,因此使用MetaMask可以非常方便地在瀏覽器中完成以太坊轉賬等操作。

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

     

        操作步驟

         安裝、啟動Ganache

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

    2. 打開程序后,會顯示以下界面,用戶可以查看賬戶(默認創建10個賬戶)、區塊、交易和日志。

     

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

     

    此時,Ganache已經在本機運行了一個以太坊私有網絡,并綁定了8545端口。

     

        安裝、啟動MetaMask

    1. 把插件添加到chrome擴展程序即可

    2. 點擊Chrome中的MetaMask圖標,按照每一步提示啟動MetaMask

    3. 如下圖所示,設置MetaMask連接到本地的以太坊私有網絡

        

    此時,MetaMask就可以和本地的以太坊私有網絡進行交互了。

     

        用MetaMask測試私有網絡

    1. 從Ganache創建的賬戶中選擇一個導入到MetaMask中

        a. 在Ganache賬戶頁面選定一個賬戶,點擊最右邊的小鑰匙圖標,復制其私鑰(private key)

        b. 在MetaMask中點擊頭像,選擇 “import account”,彈出對話框

        c.  把復制的賬戶私鑰填入文本框中,并點擊“import”

     

    此時,MetaMask就可以操作這個新賬戶了。

     

    2. 用新導入的賬戶進行轉賬

        a. 點擊“send”按鈕,彈出轉賬對話框

        b. 從Ganache賬戶頁面中,再選定一個其他的賬戶,復制其地址

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

        d. 點擊next,彈出轉賬確認框,點擊“confirm”確認交易

        e. 提醒轉賬成功后,可以看到賬戶余額發生了變化,此時再轉到Ganache賬戶頁面,也可看到兩個賬戶的余額也都發生了變化。

     

        注意

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

    如果想保留Ganache每一次運行時的交易數據,以便下一次繼續使用,可以使用命令行的形式ganache-cli啟動Ganache,并指定數據存儲目錄
    ---------------------
    作者:BigCuttie
    來源:CSDN
    原文:https://blog.csdn.net/starleelzx/article/details/82943530
    版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

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

    webstrom下載安裝

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

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

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

    僅列出標題
    共38頁: First 上一頁 5 6 7 8 9 10 11 12 13 下一頁 Last 
    主站蜘蛛池模板: 久久久久免费看黄a级试看| 内射无码专区久久亚洲| 一个人看的免费视频www在线高清动漫| 亚洲va无码va在线va天堂| 夫妻免费无码V看片| 国产免费无码AV片在线观看不卡| 一本天堂ⅴ无码亚洲道久久| 亚洲av无码精品网站| 国产精品另类激情久久久免费| 久久午夜夜伦鲁鲁片无码免费| 无遮挡a级毛片免费看| 亚洲白嫩在线观看| 亚洲熟妇无码另类久久久| 日本19禁啪啪无遮挡免费动图| 午夜免费福利小电影| 一级毛片人与动免费观看| 亚洲AV无码无限在线观看不卡| 亚洲av永久无码精品漫画| 亚洲精品无码激情AV| 啦啦啦www免费视频| 亚洲电影免费观看| 国产拍拍拍无码视频免费| 免费人成大片在线观看播放| 亚洲七久久之综合七久久| 1区1区3区4区产品亚洲| 亚洲精品夜夜夜妓女网| 亚洲国产精品激情在线观看| 国产高清在线免费| 成年女人毛片免费播放视频m| 久久久久成人精品免费播放动漫| av片在线观看永久免费| 18禁亚洲深夜福利人口| 亚洲精品无码一区二区 | 亚洲a∨无码一区二区| 亚洲人成电影网站| 亚洲综合久久久久久中文字幕| 亚洲国产精品成人精品无码区在线| 亚洲日本韩国在线| 亚洲国产成人精品女人久久久| 日韩伦理片电影在线免费观看| 毛片a级三毛片免费播放|