繁体   English   中英

松露智能合约错误:参数数量无效

[英]Truffle Smart Contract Error: Invalid number of parameter

我跟着 quorum with truffle 教程: 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 参数..

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

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

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

$ npm install -g truffle@4.1.10

并将 truffle truffle-config.jsSimpleStorage.sol solidity 版本更改为0.4.24,然后在迁移文件中重新添加privateFor。

问题解决了!

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

truffle uninstall -g

进而

npm install -g truffle@4.1.10

非常感谢@TS28

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

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

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

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

开放更正

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM