代码之家  ›  专栏  ›  技术社区  ›  BlockchainProgrammer

Truffle智能合约错误:参数数目无效

  •  0
  • BlockchainProgrammer  · 技术社区  · 6 年前

    我在《块菌法定人数》的指导下: 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)
    };
    

    但我需要这个参数。

    有人知道怎么解决这个问题吗?

    2 回复  |  直到 6 年前
        1
  •  1
  •   TS28    6 年前

    嘿@blockchainprogrammer。感谢您指导我如何使用仲裁代理。它奏效了。

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

    $ npm install -g truffle@4.1.10
    

    并将solidity的版本更改为0.4.24 truffle-config.js 以及 SimpleStorage.sol 并在迁移文件中添加back privatefor。

        2
  •  0
  •   BlockchainProgrammer    6 年前

    问题解决了!

    我要做的是将松露降级为“4.1.10”,包括:

    truffle uninstall -g
    

    然后

    npm install -g truffle@4.1.10
    

    多亏了@ts28

    推荐文章