0

我跟着松露的仲裁教程:https ://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains

现在我想将 SimpleStorage.sol 智能合约迁移到区块链,但我想让它添加“PrivateFor”参数。

这是我的智能合约:

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

这是我的:2_deploy_simplestorage.js

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

module.exports = function(deployer) {
  deployer.deploy(SimpleStorage, 42, {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};

但是当我做松露迁移时,我得到了这个错误:

$ 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.
   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:                   0 ETH


2_deploy_simplestorage.js
=========================

   Deploying 'SimpleStorage'
   -------------------------
Error:  *** Deployment Failed ***

"SimpleStorage" -- Invalid number of parameters for "undefined". Got 2 expected 1!.

    at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.1 (core: 5.0.1)
Node v8.11.4

当我不添加“privateFor”参数时,它可以工作:

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

module.exports = function(deployer) {
  deployer.deploy(SimpleStorage, 42)
};

但我需要这个 privateFor 参数..

有人知道如何解决这个问题吗?

4

3 回答 3

2

嘿@BlockChainProgrammer。感谢您指导我如何使用 Quorum 代理。有效。

对于此错误,请尝试将您的松露版本升级/降级到 v4.1。

$ npm install -g truffle@4.1.10

truffle-config.js并在您的和SimpleStorage.sol迁移文件中将solidity 的版本更改为0.4.24并添加回privateFor。

于 2019-01-24T05:00:19.673 回答
0

在这种法定人数的情况下,

 {
   privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
 };

没有在合同中定义,并且出现这样的错误,但特定的松露编译器与 Quorum 功能兼容。

但是对于像我这样的非 Quorum 用户,错误通常意味着,在你的合约中定义一个变量而不是编译器问题。很可能是构造函数中未设置的参数。

开放更正

于 2020-02-27T12:08:52.143 回答
-1

问题解决了!

我要做的是将松露降级到“4.1.10”:

truffle uninstall -g

进而

npm install -g truffle@4.1.10

非常感谢@TS28

于 2019-01-24T08:48:12.817 回答