pragma solidity ^0.4.23;


contract IDFactory is Ownable {

    Whitelisted whitelist;

    event IDCreated(uint id, address idContractAddress);

    mapping (uint => address) public ids;

    modifier idExists(uint id) {
      constructor() public {
        owner = msg.sender;
        whitelist = new Whitelisted(owner);

Hello, i'm trying to compile a solidity contract using truffle. The contract is called IDFactory.sol. When I execute truffle compile I get this error:

MacBook-Pro-de-Alicia-2:a alicialombarte$ truffle compile
TypeError: Error parsing /Users/alicialombarte/notary-contract/a/contracts/IDFactory.sol: Cannot read property '2' of null
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/~/truffle-compile/parser.js:171:1
    at Array.map (<anonymous>)
    at Object.parseImports (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/~/truffle-compile/parser.js:167:6)
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/~/truffle-compile/profiler.js:302:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-resolver/index.js:79:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-resolver/~/async/internal/onlyOnce.js:12:1
    at next (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-resolver/~/async/whilst.js:68:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-resolver/index.js:64:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-resolver/fs.js:85:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-resolver/~/async/internal/once.js:12:1

I don't have any '2' in my contract.


Here are the other 2 contracts:

pragma solidity ^0.4.23;


contract ID{

    uint id;
    Whitelisted whitelist;
    mapping (string => MessageData) public messages;

    event MessageSaved(string messageHash);

    constructor(uint _id, address _whitelist) public {
        owner = msg.sender;
        id = _id;
        whitelist = Whitelisted(_whitelist);

    struct MessageData {
        string messageSender;
        uint64 timestamp;

pragma solidity ^0.4.23;

import 'Ownable.sol';

contract Whitelisted is Ownable {

    constructor(_owner) public {
        owner = _owner;

    mapping(address => bool) internal whitelistedAddresses;

    function isWhitelisted(address addr) internal view returns (bool) {
        return whitelistedAddresses[addr];

    function addToWhitelist(address addr) public onlyOwner {
        whitelistedAddresses[addr] = true;

    function removeFromWhitelist(address addr) public onlyOwner {
        whitelistedAddresses[addr] = false;

    modifier onlyWhitelisted {
  • can you provide the code for Whilisted and ID contracts? – Jaime May 26 '18 at 10:01
  • @Jaime I added the contracts :) – Alicia May 26 '18 at 10:34
  • I added an answer, let me know how it goes. – Jaime May 26 '18 at 11:17

I put all the contracts on remix and some errors are shown:

In Whitelisted contract:

constructor(_owner) public {
        owner = _owner;

Should be:

constructor(address _owner) public {
        owner = _owner;

ID contract should be Ownable to use the owner variable or can be Whitelisted.

Also, you have a mapping

mapping (string => MessageData)

This uses a string as a key, and this is not yet implemented in solidity. you could define this as a bytes32 if your strings fit. You can not use dynamic array variables as a key.

I hope this help.


This error is not a problem with your Solidity code.

This type of error is given by the React.js. Seems that you are modeling some object and trying to access it's second property. Then, probably the object's acquisition is not well done and the var/object is null.

Because of that, when you try to access to it's properties you can't do it, because you can not access to a property of null, it just hasn't got any properties.

Recheck your React code and try to find the null object you are accessing to it's second property. Then, try to get it from the blockchain correctly in order to don't get a null instead of the correct data.

Hope it helps.

  • Hello, thanks for the help, but I'm not using react.js I'm just trying to compile the contracts, you think it might be because the connection with my node, maybe some of the parameters, like the accounts are missing? My truffle version is Truffle v4.1.7 (core: 4.1.7) and I'm using Ganache for my node – Alicia May 26 '18 at 10:31
  • Did you try to compile the contract on Remix? Try it and look if you get the same error. – CPereez19 May 26 '18 at 10:50
  • 1
    With Remix works, i'll try to reinstall Truffle. Thanks! – Alicia May 26 '18 at 10:54
  • The error only appears when i import the Whitelisted contract (Whitelisted.sol) , in Remix i didn't import it, importing other things like Ownable works. – Alicia May 26 '18 at 11:09
  • The correction posted by @Jaime I think will make it work without throwing errors. – CPereez19 May 26 '18 at 11:17

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.