1

I'm using Web3.js (@1.0) and not @0.2

This is really annoying !

My Private blockchain is running thanks to the following command : vgeth --datadir "T:\Programs\Ethereum\Own\" --networkid 2154 --rpc --rpccorsdomain "*" console

Here, how a deploy my contract: (deploy.js)

var Web3 = require('web3');
const compiledContract = require('./App');
const localhost = "http://localhost:8545";
const web3 = new Web3(new Web3.providers.HttpProvider(localhost));
const App = new web3.eth.Contract(compiledContract.abi);

var deployInstance = App.deploy({data: compiledContract.bytecode});
deployInstance.estimateGas(function(err, gas){
   console.log("gasestimate " + gas);
   web3.eth.getCoinbase().then(function(coinbase){
     console.log("coinbase " + coinbase);
     deployInstance.send({from: coinbase, gas: gas+4000}, function(error, transactionHash){})
  .on('transactionHash', function(hash){console.log("hash : " + hash); })
  .on('receipt', function (receipt) { console.log("Address: " + receipt.contractAddress); })
  .on('error', console.error);
   });
});

That's working pretty good, and my contract is deployed. I obviously though to unlock an account (here eth.coinbase) and to call miner.start() and miner.stop() when the contract was finally mined

Then that's how I call my methods. This is a sample code: (call.js)

var Web3 = require('web3');
const compiledContract = require('./App');
const localhost = "http://localhost:8545";
const address = "0x84C210471f7C58b547129E62cdDC2D365d307212"; //address returned after deployed phase

var web3 = new Web3(new Web3.providers.HttpProvider(localhost));
var Contract = new web3.eth.Contract(compiledContract.abi, address);

set();
//get();

function get(){
   Contract.methods.getTest().call(function(err, result){
     if(err) console.log(err);
     else console.log(result);
   });
}

function set(){
   web3.eth.getCoinbase().then(function(coinbase){
      web3.eth.personal.unlockAccount(coinbase, "", function(err) {
        Contract.methods.setTest("ugonnawork").send({from: coinbase, gas: 300000}, function(error, transactionHash){})
    .on('transactionHash', function(hash){console.log("hash : " + hash); })
    .on('error', console.error);
  });
 });
}

And this annoying issue occurred :

Geth - Web3 : Invalid number of parameters for "MyMethod". Got 0 expected 1!

When I call another method called getUser(uint index) I got : Geth - Web3 : Invalid number of parameters for "MyMethod". Got 1 expected 2!

And when I call name() that's working pretty good, and my ERC20 Token name is returned.

It seems that fails or works randomly but it can't figure out what's wrong

Please help

  • I had similar issues, but mine were related to using the 1.0 web3.js API. Mind posting your contract or ABI code if you're still experiencing this issue? – Tomislav Markovski Feb 19 '18 at 16:37
  • I'm seeing this too. Did you ever figure this out? – fraxture May 9 '18 at 0:18
  • Yes I figured out by downgrading to 0.2 but it was so many months ago. I don't know what's going on nowadays.. – nicolas.grd May 13 '18 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.