admin管理员组文章数量:1323524
I'm trying to deploy my first Voting contract on the testRPC and the below is my code.. for some reason it's plaining when I e to deploy.
The error seems to be from the arguments parameter. I tried passing an empty array and it said "Got 0 expected 1!". I tried passing just one name and it says "value.forEach" is not a function.
Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
sourceCode = fs.readFileSync('Voting.sol').toString()
solc = require('solc')
piledCode = solcpile(sourceCode)
abiDefinition = JSON.parse(piledCode.contracts[':Voting'].interface)
VotingContract = new web3.eth.Contract(abiDefinition)
byteCode = piledCode.contracts[':Voting'].bytecode
VotingContract.deploy({
data: byteCode,
arguments:['Joseph','Sean','Matthew']
}).send({
from: '0x00D1AE0A6fC13B9ecdefA118B94cF95ac16D4ab0',
gas: 4700000
})
.on('error', function(error) {
console.log(error);
}
.then(function(newContractInstance) {
console.log(newContractInstance.options.address)
}
I'm trying to deploy my first Voting contract on the testRPC and the below is my code.. for some reason it's plaining when I e to deploy.
The error seems to be from the arguments parameter. I tried passing an empty array and it said "Got 0 expected 1!". I tried passing just one name and it says "value.forEach" is not a function.
Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
sourceCode = fs.readFileSync('Voting.sol').toString()
solc = require('solc')
piledCode = solc.pile(sourceCode)
abiDefinition = JSON.parse(piledCode.contracts[':Voting'].interface)
VotingContract = new web3.eth.Contract(abiDefinition)
byteCode = piledCode.contracts[':Voting'].bytecode
VotingContract.deploy({
data: byteCode,
arguments:['Joseph','Sean','Matthew']
}).send({
from: '0x00D1AE0A6fC13B9ecdefA118B94cF95ac16D4ab0',
gas: 4700000
})
.on('error', function(error) {
console.log(error);
}
.then(function(newContractInstance) {
console.log(newContractInstance.options.address)
}
Share
Improve this question
edited May 30, 2022 at 19:53
TylerH
21.1k77 gold badges79 silver badges112 bronze badges
asked Aug 19, 2017 at 20:06
OcirneOcirne
3231 gold badge6 silver badges16 bronze badges
2 Answers
Reset to default 6In the migrations, add your args in the deployer.
// Deploy a single contract with constructor arguments
deployer.deploy(A, arg1, arg2, ...);
where A is your smart contract, arg1, arg2 etc are the arguments
This is mentioned in the documentation: https://www.trufflesuite./docs/truffle/getting-started/running-migrations#deployer-deploy-contract-args-options-
Try something like this for contracts that need constructor arguments
var bytecodeWithParam = MyContract.new.getData(
param1,
param2,
{ data: piledByteCode });
It is this bytecodeWithParam that you paste into the "Byte Code" field. If you look at it in detail, you will see param1 and param2 32-byte packed at the end.
Another Example
var MyContract = web3.eth.contract(abiArray);
// instantiate by address
var contractInstance = MyContract.at(address);
// deploy new contract
var contractInstance = MyContract.new([constructorParam1] [, constructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000});
// Get the data to deploy the contract manually
var contractData = MyContract.new.getData([constructorParam1] [, constructorParam2], {data: '0x12345...'});
// contractData = '0x12345643213456000000000023434234'
https://github./ethereum/wiki/wiki/JavaScript-API#web3ethcontract
本文标签:
版权声明:本文标题:javascript - Getting Invalid number of parameters for "undefined" when deploying smart contract - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132477a2422224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论