0

I have the following two smart contracts in the same ".sol" file: Credentials and Proposals. Every Proposals smart contract should refer to a single Credentials smart contract, in order to do that, when Proposals is created (constructor method) it instatiates a Credentials smart contracts as you can see below.

Credentials.sol:

contract Credentials {

    uint256 _numberOfProviders;
    mapping(address => bool) public _owners;
    uint256 _numberOfOwners;

    constructor(address[] memory owners) payable{
        _owners[msg.sender] = true;
        _numberOfOwners = 1;
        for (uint i=0; i<owners.length; i++) {
            if(false == _owners[owners[i]]){
                _owners[owners[i]] = true;
                _numberOfOwners += 1;
            }
            
        }
        _numberOfProviders = 0;
    }
}

Proposals.sol:

contract Proposals {

    Credentials  _credentialsContract;
    address payable _chairperson;
    
    constructor() payable{
        _chairperson = payable(msg.sender);
        address[] memory listOfOwners;
        listOfOwners[0] = msg.sender;
        _credentialsContract = new Credentials(listOfOwners);
    }
}

In Remix the compiler works but when I try to deploy Proposals I get the following error which I do not understand:

creation of Proposals errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

0

You can try this:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;
contract Credentials {

    uint256 _numberOfProviders;
    mapping(address => bool) public _owners;
    uint256 _numberOfOwners;

    constructor(address[] memory owners) payable{
        _owners[msg.sender] = true;
        _numberOfOwners = 1;
        for (uint i=0; i<owners.length; i++) {
            if(false == _owners[owners[i]]){
                _owners[owners[i]] = true;
                _numberOfOwners += 1;
            }
            
        }
        _numberOfProviders = 0;
    }
}

contract Proposals{

    Credentials  _credentialsContract;
    address payable _chairperson;
    address[] listOfOwners;
    constructor() payable{
        _chairperson = payable(msg.sender);
        listOfOwners.push(address(msg.sender));
        _credentialsContract = new Credentials(listOfOwners);
    }
}
1
  • Thank you very much for your reply @DharmveersinhJadeja, nevertheless isn't more expensive (from the GAS point of view) to execute smart contracts where data is stored as properties? wouldn't it be better to somehow save the "listOfOwner" as a "memory" variable inside the constructor method? – Alberto Molina Apr 7 at 13:03

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.