Lv.的博客

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

Now I want to migrate the SimpleStorage.sol Smart Contract to the blockchain, but I want to make it to add the "PrivateFor" parameter.

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

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:

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

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

But I need this privateFor parameter..

Does someone know how to fix this?

 
 
1
 

Hey @BlockChainProgrammer. Thanks for guiding me on how to use the Quorum proxy. It worked.

For this error, Try to upgrade/downgrade your truffle version to 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.

  

Problem solved!

What I had to do is to downgrade truffle to "4.1.10" with:

truffle uninstall -g

and then

npm install -g truffle@4.1.10

 

 
posted @ 2019-07-17 14:18  Avatarx  阅读(916)  评论(0编辑  收藏  举报