I have this contract and deployed it to my local client (ganache gui) and its abi.json file (of solc compiler generated). The third file is param.txt which contains encoded functions with arguments which then saved into an array and takes elements one by one . [0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0,0x25468f680000000000000000000000000000000000000000000000000000000000000000,0xed2b5a3c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] the first one is about constructor with its arguments and from second to onward are some of its encoded functions with arguments. My task is to send these encoded functions with parameters to that contract (deployed at localhost - Ganache GUI). My code works for contract whose constructor s without arguments, but give error for constructor with arguments.

Here is my code:

 async function dep(r) {

    const contract = new web3.eth.Contract(myAbi[r]);

      for(i=0; i<1; i++) {

      if(constructorParams[i]=='0x'){ // checking first element of above array is 0x (means constructor with no arguments).. 
// if this true, then my code works, if constructor have some arguments then error
        params = {
          data: '0x' + myBin[r]
        params = {
          //  data: '0x' + myBin[r]+constructorParams[i]
          data: '0x' + myBin[r],
          arguments: constructorParams[1]

    const transaction = contract.deploy(params); // here is error 
    const options = {
        data: transaction.encodeABI(),
        gas: await transaction.estimateGas({from: account1})

    const signed = await web3.eth.accounts.signTransaction(options, privateKey1);
    receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
    console.log(`Contract deployed at address: ${receipt.contractAddress}`);

I just want to know following two things;

  1. In above encoded array, is constructor encoded properly or not ?
    1. If enconded constructor is true, then why this error ?
    2. i have taken bin .as myAbi from json file, should I have to take this bin or should i have to take bin-runtime to deploy contract.

Here is my error:

UnhandledPromiseRejectionWarning: TypeError: CreateListFromArrayLike called on non-object
    at Contract.deploy (C:\Users\aa\node_modules\web3-eth-contract\src\index.js:510:33)
    at dep (C:\Users\aa\Desktop\temp\deploy - fromsFuzz.js:133:30)
    at main (C:\Users\aa\Desktop\temp\deploy - fromsFuzz.js:198:27)
    at Object.<anonymous> (C:\Users\aa\Desktop\temp\deploy - fromsFuzz.js:214:3)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
    at internal/main/run_main_module.js:17:11
(node:20300) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:20300) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

UPDATE: I have change argument : constructorParams[1] to arguments: [constructorParams[1]], but then my encoded constructor treated as one argument which shows following error;

Error: Invalid number of parameters for "undefined". Got 1 expected 2!


constructorParams[1] = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0

UPDATE 3: my constructor in contract which i want to call is = constructor(address moneyMarket, address liquidator) LiquidationChecker(moneyMarket, liquidator) {}. Now, anyone can tell me that whether in above constructorParams, i am encoding these two addressess (moneyMarket and liquidator) correctly or not ?

UPDATE 4: if i deploy my above contract using sendTransaction like below;

      params = '0x' + myBin[r]
        params= '0x' + myBin[r]+constructorParams[0]

try {
  await web3.eth.sendTransaction(
    data: params
        }, function(err, receipt) {console.log(receipt)});
} catch (error) {
  console.log(" ERROR !", error); 

then it give following error;

Error: Returned error: base fee exceeds gas limit
  • The bottom part looks like a piece of code that I gave you (?). Which line in your code triggers this error? Commented Dec 9, 2019 at 11:45
  • BTW, unless constructorParams[1] is an array, you should change arguments: constructorParams[1] to arguments: [constructorParams[1]]. Commented Dec 9, 2019 at 11:46
  • yes, it was your code, i already mentioned the line, see code where ' const transaction = contract.deploy(params); // here is error'
    – Amir Ali
    Commented Dec 9, 2019 at 12:36
  • i have changed , but it gives this error .. Error: Invalid number of parameters for "undefined". Got 1 expected 2!... Can you confirm my encoded constructor with parameters is true ?
    – Amir Ali
    Commented Dec 9, 2019 at 12:37
  • also i have provided update as per your comments. see my update
    – Amir Ali
    Commented Dec 9, 2019 at 12:40


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.