Skip to content

Commit

Permalink
Fix unreliable array test in Contract package (#1013)
Browse files Browse the repository at this point in the history
Using node.js 6.11.2 I get the following error when trying to instantiate contracts:
> jsonInterface instanceof Array
true
> new web3.eth.Contract(jsonInterface)
Error: You must provide the json interface of the contract when instatiating a contract object.

Although jsonInterface instanceof Array evaluates to true, the exact same test condition evaluates to false within the Contract constructor with the passed down json interface. Using either "Array.isArray(jsonInterface)" or "toString.call(jsonInterface) === '[object Array]'" as a test condition instead fixes the issue.

Also the typo in the error message got corrected.
  • Loading branch information
microraptor authored and frozeman committed Sep 15, 2017
1 parent 8acc3d3 commit 18dffea
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/web3-eth-contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ var Contract = function Contract(jsonInterface, address, options) {
throw new Error('Please use the "new" keyword to instantiate a web3.eth.contract() object!');
}

if(!jsonInterface || !(jsonInterface instanceof Array)) {
throw new Error('You must provide the json interface of the contract when instatiating a contract object.');
if(!jsonInterface || !(Array.isArray(jsonInterface))) {
throw new Error('You must provide the json interface of the contract when instantiating a contract object.');
}

// add custom send Methods
Expand Down

0 comments on commit 18dffea

Please sign in to comment.