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
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 Apr 7 '18 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) – sunwarri0r Feb 12 '19 at 17:14

Your Answer

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

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