1

我实际上正在学习以太坊上的智能合约编程,并且使用松露。现在我在这里制作本教程:https ://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains

您可以在其中学习如何创建具有法定人数的 dapp。但现在我有一个问题。

我完全按照描述做了所有事情,但是当我这样做时:

truffle migrate

我在这里收到此错误:

$ truffle migrate
    ⚠️  Important ⚠️
    If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.


    Starting migrations...
    ======================
    > Network name:    'development'
    > Network id:      10
    > Block gas limit: 3758096384


    1_initial_migration.js
    ======================

       Deploying 'Migrations'
       ----------------------
       > transaction hash:    0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
    - Blocks: 0            Seconds: 0
       > Blocks: 0            Seconds: 0
       > contract address:    0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
       > account:             0xed9d02e382b34818e88B88a309c7fe71E65f419d
       > balance:             1000000000
       > gas used:            245462
       > gas price:           0 gwei
       > value sent:          0 ETH
       > total cost:          0 ETH


    - Saving migration to chain.
    Error: Number can only safely store up to 53 bits
        at assert (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\number-to-bn\~\bn.js\lib\bn.js:6:1)
        at BN.toNumber (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\number-to-bn\~\bn.js\lib\bn.js:506:1)
        at Object.hexToNumber (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-utils\src\utils.js:234:1)
        at Method.outputBlockFormatter [as outputFormatter] (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-helpers\src\formatters.js:239:1)
        at Method.formatOutput (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-method\src\index.js:163:1)
        at sendTxCallback (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-method\src\index.js:473:1)
        at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-core-requestmanager\src\index.js:147:1
        at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:145:1
        at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:112:1
        at XMLHttpRequest.request.onreadystatechange (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\web3-providers-http\src\index.js:96:1)
        at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
        at XMLHttpRequest._setReadyState (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)
        at XMLHttpRequest._onHttpResponseEnd (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)
        at IncomingMessage.<anonymous> (C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:289:47)
        at emitNone (events.js:111:20)
        at IncomingMessage.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1064:12)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
    Truffle v5.0.1 (core: 5.0.1)
    Node v8.11.4

现在不知道为什么...

有没有人有同样的问题,可以在这里帮助我吗?

这是我的智能合约:

pragma solidity ^0.4.17;

contract SimpleStorage {
  uint public storedData;

  constructor(uint initVal) public {
    storedData = initVal;
  }

  function set(uint x) public {
    storedData = x;
  }

  function get() view public returns (uint retVal) {
    return storedData;
  }
}

还有我的 truffle-config.js 文件:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 22000, // was 8545
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodefour:  {
      host: "127.0.0.1",
      port: 22003,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodeseven:  {
      host: "127.0.0.1",
      port: 22006,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    }
  },
  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.4.25",    // Fetch exact version from solc-bin (default: truffle's version)
    }
  }
}

和迁移文件:

var SimpleStorage = artifacts.require("SimpleStorage");

module.exports = function(deployer) {
  // Pass 42 to the contract as the first constructor parameter
  deployer.deploy(SimpleStorage, 2, { privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="] })
};
4

6 回答 6

4

所以问题是块时间戳以纳秒为单位。

@edgraaff 编写了一个代理,将时间戳从纳秒转换为秒。你可以在这里找到代码-> https://github.com/edgraaff/quorum-rpc-proxy

我要做的是克隆代理并将 config.js 文件更改为:

module.exports = {
  rpcUrl: 'http://localhost:22000',
  port: 7545
};

在 truffle-config.js 文件中,我不得不更改端口。这是代码:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545, // was 8545
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodefour:  {
      host: "127.0.0.1",
      port: 22003,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    },
    nodeseven:  {
      host: "127.0.0.1",
      port: 22006,
      network_id: "*", // Match any network id
      gasPrice: 0,
      gas: 4500000
    }
  },
  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.4.25",    // Fetch exact version from solc-bin (default: truffle's version)
    }
  }
}

感谢@edgraaff

于 2019-01-18T15:08:19.030 回答
4

代理是不够的,因为 web3.js 可以通过 ws 获取订阅中的阻塞

同样在 quorum 中按数字获取块被破坏,它只接受十六进制,但是 web3.js 假定十六进制为块哈希

这是我的解决方案

web3.extend({
  property: 'eth',
  methods: [new web3.extend.Method({
    name: 'getBlockByNumber',
    call: 'eth_getBlockByNumber',
    params: 2,
    inputFormatter: [web3.extend.formatters.inputBlockNumberFormatter, v => !!v],
    outputFormatter: web3.extend.formatters.outputBlockFormatter
  })]
});
web3.utils.hexToNumber = v => {
  if (!v) return v;
  try {
    return numberToBN(v).toNumber();
  } catch (e) {
    return numberToBN(v).toString();
  }
};

请注意时间戳现在是字符串

这是 web3.js 存储库中的相关问题https://github.com/ethereum/web3.js/issues/1215

于 2019-02-08T15:08:44.810 回答
2

简单修复:只需为应该在仲裁上运行的网络添加type: "quorum"truffle -config

于 2019-06-03T08:55:18.040 回答
2

目前(2020 年 5 月),基本上您有两种解决方法:

  1. 添加type: "quorum"truffle-config.js喜欢networks.js
    myLocalQuorum: {
      protocol: 'http',
      host: 'localhost',
      port: 22000,
      gas: 5000000,
      gasPrice: 0,
      networkId: '*',
      type: "quorum"
    },
  1. 如果您正在使用@truffle/hd-wallet-provider,则没有简单的解决方法,但您可以将您的共识切换为 ,istanbul而不是raft,请参阅oz 社区了解更多详细信息。

在运行默认的共识伊斯坦布尔 BFT 时,我可以使用 Truffle 和 OpenZeppelin SDK 部署合约并与之交互。

当我切换到 RAFT 时,我无法使用 truffle migrate 或 oz create 部署合约。在 RAFT 的 Truffle 文档中,我没有看到我需要明智地进行配置的任何不同之处。通过@abcoathup

于 2020-05-19T07:28:35.727 回答
1

如果您将 truffle 版本降级到 4.1.15,则不需要使用任何代理。如果你这样做,一切都会好起来的。只是不要降级到 4.1.14,因为 truffle init 它在那个包中坏了!

于 2019-03-22T13:28:31.490 回答
0

@QuorumPrivateBlockChain 嘿伙计。

所以这是我的 truffle-config.js 文件:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*",
      gasPrice: 0,
      gas: 4500000
    },
    nodefour:  {
      host: "127.0.0.1",
      port: 7546,
      network_id: "*",
      gasPrice: 0,
      gas: 4500000
    },
    nodeseven:  {
      host: "127.0.0.1",
      port: 7547,
      network_id: "*",
      gasPrice: 0,
      gas: 4500000
    }
  },
  compilers: {
    solc: {
      version: "0.4.25",   
    }
  }
}

这是我来自代理的 config.js 文件:

module.exports = [
  {
    rpcUrl: 'http://localhost:22000',
    port: 7545
  },
  {
    rpcUrl: 'http://localhost:22003',
    port: 7546
  },
  {
    rpcUrl: 'http://localhost:22006',
    port: 7547
  },
];

所以你做什么,你从你的松露发送请求到你的代理,然后代理转换时间戳并将请求进一步发送到节点。

代理本身就是一个程序,您不必从代理代码中复制 config.js 文件。查看 github 如何启动代理。

于 2019-01-22T11:55:37.937 回答