Truffle Smart Contract Error: Invalid number of parameter
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 时,出现此错误:
$ 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 代理。成功了。
对于这个错误,尝试upgrade/downgrade你的truffle版本到v4.1。
$ npm install -g truffle@4.1.10
并在 truffle-config.js
和 SimpleStorage.sol
中将 solidity 版本更改为 0.4.24,并在迁移文件中添加回 privateFor。
问题已解决!
我要做的是将 truffle 降级为“4.1.10”:
truffle uninstall -g
然后是
npm install -g truffle@4.1.10
非常感谢@TS28
在这种情况下,
{
privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
没有在合同中定义,并且出现了这样的错误,但是特定的松露编译器与 Quorum 功能兼容。
但对于像我这样的非 Quorum 用户
该错误通常意味着在您的合同中定义了一个变量,而不是编译器问题。很可能是构造函数中未设置的参数。
欢迎更正
我遵循了 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 时,出现此错误:
$ 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 代理。成功了。
对于这个错误,尝试upgrade/downgrade你的truffle版本到v4.1。
$ npm install -g truffle@4.1.10
并在 truffle-config.js
和 SimpleStorage.sol
中将 solidity 版本更改为 0.4.24,并在迁移文件中添加回 privateFor。
问题已解决!
我要做的是将 truffle 降级为“4.1.10”:
truffle uninstall -g
然后是
npm install -g truffle@4.1.10
非常感谢@TS28
在这种情况下,
{
privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
没有在合同中定义,并且出现了这样的错误,但是特定的松露编译器与 Quorum 功能兼容。
但对于像我这样的非 Quorum 用户 该错误通常意味着在您的合同中定义了一个变量,而不是编译器问题。很可能是构造函数中未设置的参数。
欢迎更正