简体   繁体   English

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

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

I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains我跟着 quorum with truffle 教程: https : //truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains

Now I want to migrate the SimpleStorage.sol Smart Contract to the blockchain, but I want to make it to add the "PrivateFor" parameter.现在我想将 SimpleStorage.sol 智能合约迁移到区块链,但我想让它添加“PrivateFor”参数。

This is my Smart Contract:这是我的智能合约:

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

This is my: 2_deploy_simplestorage.js这是我的:2_deploy_simplestorage.js

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

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

But when I do truffle migrate, I get this error:但是当我做松露迁移时,我收到这个错误:

$ 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

When I don't add the "privateFor" parameter, it works:当我不添加“privateFor”参数时,它可以工作:

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

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

But I need this privateFor parameter..但我需要这个 privateFor 参数..

Does someone know how to fix this?有人知道如何解决这个问题吗?

Hey @BlockChainProgrammer.嘿@BlockChainProgrammer。 Thanks for guiding me on how to use the Quorum proxy.感谢您指导我如何使用 Quorum 代理。 It worked.有效。

For this error, Try to upgrade/downgrade your truffle version to v4.1.对于此错误,请尝试将您的 truffle 版本升级/降级到 v4.1。

$ npm install -g truffle@4.1.10

and change the version of solidity to 0.4.24 in your truffle-config.js and the SimpleStorage.sol and add back privateFor in your migration file.并将 truffle truffle-config.jsSimpleStorage.sol solidity 版本更改为0.4.24,然后在迁移文件中重新添加privateFor。

Problem solved!问题解决了!

What I had to do is to downgrade truffle to "4.1.10" with:我必须做的是将松露降级到“4.1.10”:

truffle uninstall -g

and then进而

npm install -g truffle@4.1.10

Many thanks to @TS28非常感谢@TS28

In this case of quorum, the在这种法定人数的情况下,

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

was not defined in the contract, and at such the error, but that particular truffle compiler is compatible with Quorum features.没有在合同中定义,并且在这样的错误中,但特定的松露编译器与 Quorum 功能兼容。

But For non-Quorum users like myself The error Usually means, define a variable in your contract and not a compiler problem.但是对于像我这样的非 Quorum 用户 错误通常意味着,在你的合约中定义一个变量而不是编译器问题。 Most likely a parameter not set in the constructor.很可能是未在构造函数中设置的参数。

Open to corrections开放更正

暂无
暂无

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

相关问题 尝试在松露快递盒中使用智能合约写入数据时出现无效地址错误 - Getting an Invalid Address error when trying to write data with smart contract in truffle express box Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程 - Truffle and Ganache tutorial for a Solidity smart contract migration error 在 Truffle 上测试部署的智能合约 - Testing Deployed Smart Contract on Truffle 错误 - 当调用部署在松露智能合约上时,等待仅在异步 function 中有效 - Error - await is only valid in async function, when calling deployed on a truffle smart contract 部署智能合约时获取“未定义”的参数数量无效 - Getting Invalid number of parameters for “undefined” when deploying smart contract 执行truffle.migrate时发生错误,“ undefined”的参数数量无效 - An error when executing truffle.migrate, Invalid number of parameters for “undefined” 测试我的 Solidity 智能合约时遇到问题(带松露) - Having a Problem Testing my Solidity Smart Contract (w/ Truffle) 无法使用 Truffle Infura 将智能合约部署到测试网 (Ropsten) - Unable to deploy smart contract to testnet (Ropsten) using Truffle Infura 在 docker 上的私有区块链节点上使用 truffle 部署智能合约 - Deploying smart contract using truffle on private blockchain node on docker 测试松露中的智能合约要求:如果功能不无效,则交易将被还原 - Testing Smart contract requires in Truffle: transaction reverted if function isnt void
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM