Getting Invalid number of parameters for “undefined” when deploying smart contract

0 votes

I'm trying to deploy my first Voting contract on the testRPC and the below is my code.. I am not able to deploy it. 

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')
compiledCode = solc.compile(sourceCode)
abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface)
VotingContract = new web3.eth.Contract(abiDefinition)
byteCode = compiledCode.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)
}
Oct 10, 2018 in Blockchain by digger
• 26,550 points
524 views

1 answer to this question.

0 votes

Try something like this for contracts that need constructor arguments

var bytecodeWithParam = MyContract.new.getData(
    param1,
    param2,
    { data: compiledByteCode });

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'
answered Oct 10, 2018 by Omkar
• 67,620 points

Related Questions In Blockchain

0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 7, 2018 in Blockchain by Shashank
• 10,350 points
31 views
0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,020 points
416 views
0 votes
1 answer

How to get notified when an event triggers on ethereum smart contract?

Here's a simple example for web3js 1.0.0.beta*: function handler ...READ MORE

answered Jun 8, 2018 in Blockchain by ariaholic
• 7,340 points
409 views
0 votes
1 answer

Where are the transaction details of a smart contract is written in Ethereum?

First ques:where in the blockchain is a ...READ MORE

answered Jul 11, 2018 in Blockchain by Shashank
• 10,350 points
43 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
155 views
0 votes
1 answer
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,620 points
142 views
+1 vote
4 answers

How to estimate the cost for deploying smart contract on mainnet?

Since you have already deployed the contract ...READ MORE

answered Apr 9, 2018 in Blockchain by Shashank
• 10,350 points
1,472 views