4

This is a simple contract I am trying out with an Ethereum testrpc instance.

pragma solidity ^0.4.11;
/// @title List

// Begin contract defintion
contract List {

    struct ListMembers {
        bytes32 listOwner;
        bytes32[] members;
        uint256 rNumber;
        uint256 aNumber; 
        uint256 uNumber;  
    }

    ListMembers public lm;
    mapping (bytes32 => bool) public addedMembers;

    function List(bytes32 listOwner) {
        lm.listOwner = listOwner;
        lm.rNumber = 10000;
        lm.aNumber = 0;
        lm.uNumber = 0;
    }
}

And, this is the web3.js code to deploy the contract.

var Web3 = require('web3');
var fs = require('fs');
//
var ethHttpProvider = new Web3.providers.HttpProvider("http://localhost:8545");
var web3 = new Web3(ethHttpProvider);
var abiFile = fs.readFileSync('Lists.abi').toString();
var abiDef = JSON.parse(abiFile);
var byteCode = fs.readFileSync('Lists.bin').toString();
//
var listContract = web3.eth.contract(abiDef);
deployedContract = listContract.new('A',{data: byteCode, from: web3.eth.accounts[0], gas: 4700000});
//

And, this is the error I am getting:

TypeError: value.forEach is not a function

What am I missing?

4
  • i think the error comes from the provided constructor parameter 'A'
    – Badr Bellaj
    Commented Aug 25, 2017 at 20:06
  • Also data should have a '0x' in front. Something like {data: '0x' + byteCode ...}.
    – Ismael
    Commented Aug 26, 2017 at 1:33
  • Yes. What is the correct way of passing argument? Commented Aug 26, 2017 at 2:09
  • The correct format is to pass it as an array element as described here. So, it is, listContract.new(['A'],...) github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract Commented Aug 26, 2017 at 4:51

1 Answer 1

1

The correct format is to pass it as an array element as described in wiki. So, it is, listContract.new(['A'],...)

2
  • web3.js should be validating its input types... so this should be submitted as an issue on their github page.
    – Paul S
    Commented Apr 7, 2018 at 18:23
  • I had a similar error with passing the abi the wrong way. It helped to pass the object with a JSON.parse after require() the file. Like this JSON.parse(combinedJson.contracts.contractName.abi)
    – sunwarr10r
    Commented Feb 12, 2019 at 17:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.