Ошибка смарт-контракта 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 ..

Кто-нибудь знает, как это исправить?


person BlockchainProgrammer    schedule 22.01.2019    source источник


Ответы (3)


Привет @BlockChainProgrammer. Спасибо за советы по использованию прокси-сервера Quorum. Это сработало.

Для этой ошибки попробуйте обновить / понизить версию вашей трюфеля до v4.1.

$ npm install -g [email protected]

и измените версию solidity на 0.4.24 в ваших truffle-config.js и SimpleStorage.sol и добавьте обратно privateFor в свой файл миграции.

person exploringsincebirth    schedule 24.01.2019
comment
Спасибо друг. Я проверю это через несколько часов - person BlockchainProgrammer; 24.01.2019
comment
Здравствуйте, вы имеете в виду в SimpleStorage.sol это: pragma solidity ^4.1.24; и в файле truffle-config.js это: solc: { version: "4.1.24", }? Потому что я получаю сообщение об ошибке - person BlockchainProgrammer; 24.01.2019
comment
Верно. В обоих вам нужна одна и та же версия. У меня это сработало. - person exploringsincebirth; 24.01.2019
comment
Также попробуйте присоединиться к этой слабой группе с веб-сайта кворума. - person exploringsincebirth; 24.01.2019
comment
Здравствуйте, у меня такая ошибка: SyntaxError: Source file requires different compiler version (current compiler is 0.4.24+commit.e67f0147.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version pragma solidity ^4.1.24; - person BlockchainProgrammer; 24.01.2019
comment
и когда я пытаюсь установить версию solc 4.1.24 с npm install [email protected], я получаю эту ошибку: npm ERR! code ETARGET npm ERR! notarget No matching version found for [email protected] npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\dany.vandermeij\AppData\Roaming\npm-cache\_logs\2019-01-24T08_12_48_682Z-debug.log - person BlockchainProgrammer; 24.01.2019
comment
Я тоже не могу найти эту версию. Вы уверены, что имеете в виду версию 4.1.24? - person BlockchainProgrammer; 24.01.2019
comment
упс извините, я имел ввиду 0.4.24. Думаю, какая-то опечатка. Надеюсь, что это работает. - person exploringsincebirth; 24.01.2019
comment
Какую группу слабаков вы имеете в виду? У вас есть ссылка, что ли? - person BlockchainProgrammer; 24.01.2019
comment
github.com/jpmorganchase/constellation Внизу этой ссылки будет еще одна ссылка на их Slack-сообщество. - person exploringsincebirth; 25.01.2019

Задача решена!

Что мне нужно было сделать, так это понизить версию трюфеля до "4.1.10" с помощью:

truffle uninstall -g

а потом

npm install -g [email protected]

Большое спасибо @ TS28

person BlockchainProgrammer    schedule 24.01.2019

В случае кворума

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

не был определен в контракте, и при такой ошибке, но этот конкретный компилятор трюфеля совместим с функциями Quorum.

Но для пользователей, не входящих в кворум, таких как я. Ошибка Обычно означает определение переменной в вашем контракте, а не проблему компилятора. Скорее всего, параметр не задан в конструкторе.

Открыт для исправлений

person Tide    schedule 27.02.2020