0

I am working on a crowdfundin dapp and I have a problem while deploying a smart contract from another one.

Actually , the main smart contract called crowdFactory is supposed to invoke a smart contract for each client (ClientSC) , the first one return the address of the second one but the problem I don't know how to run functions of the second one with a specific address on solidity

here is the first smart contract

pragma solidity ^0.5.0;

pragma experimental ABIEncoderV2;

import "./sharedLib.sol";
// import "./clientSC.sol";
import "./projetSC.sol";


contract CrowdFactory {


    using sharedLib for sharedLib.Client; 
    using sharedLib for sharedLib.Projet;


//----------------------mapping--------------------   

     mapping(address => ClientSC) public usersinfo;  // contient les données des utilisateurs 
     mapping (address=> sharedLib.Projet)public projectsinfo; // contient les données des projets 
//----------------------tableau d'addresse --------------------   

    address[] public users; // contient les addresse des utilisateurs (wallet)
    address[] public clients;// contient les addresse des contract crées 
    address[] public Projects; // contient les addresses des contracts des projet crées 

//----------------------Constructeur   --------------------   

    constructor ()public {}


//----------------------Modifier  --------------------   


//----------------------event   --------------------   
event registred(address contractAddress, address publickey, uint userId ) ;
event projectAdded(address contractAddress, address porteur, uint pID ) ;
event loggedin(address publickey , uint userId);// to see who's logged in
//²project added 





//----------------------verifier l'existance d'un utilisateur -----------------------------------------
// verifier si l'addresse de l'utilisateur existe 
    function isRegistred (address _userAddress) 
    internal 
    view   
    returns(bool){
           for(uint256 i = 0; i < users.length; i++){
                if(users[i] == _userAddress) return true;
                else         return false;

           }             
    }

   //----------------------Registration-----------------------------------------

   function Registration (uint _userId,  string memory _mail ,string memory _password)   
   public
   returns (ClientSC newClient )
     {   require (!isRegistred(msg.sender));
                ClientSC newClient = new ClientSC  ( _userId, _mail , _password);
                usersinfo[msg.sender]= newClient;
                users.push(msg.sender);
                clients.push(address (newClient));
                emit registred(address(newClient),msg.sender, _userId);
                return (newClient) ;
   } 
}

here is the second one

pragma solidity ^0.5.0;

import "./projetSC.sol";
import "./sharedLib.sol";
import "./owned.sol";
import "./crowdFactory.sol";

contract ClientSC is Owned {

    using sharedLib for sharedLib.Contribution;
    using sharedLib for sharedLib.Reward; 
    using sharedLib for sharedLib.Client;
    using sharedLib for sharedLib.Projet;

        sharedLib.Client Client; 


        address public Crowdfactory;


        uint projectsNB;
        uint contributionsNB;

        mapping (uint=> sharedLib.Projet) myProjects;
        mapping (uint => sharedLib.Contribution)  myContributions; 
        mapping (uint=> sharedLib.Reward) myRewards;

//-----------------------------events--------------------------

//----------------------------- modifier--------------------------

//-----------------------------constructor--------------------------

        constructor (uint _userId,string memory _mail ,string memory _password ) public {
          //initialiser la structure client
          // ClientSC.Client.userId

            Client = sharedLib.Client({
                userId:_userId,
                mail :_mail, 
                password:_password, 
                contractAddress: address (this), 
                publickey:msg.sender 

            });

            projectsNB=0;
            contributionsNB=0;
            Crowdfactory = msg.sender;
        }


        //-----------------------------getters and setters--------------------------
        function getMyInfo () public returns (uint, string memory  , string memory, address, address,uint,uint,address) {
            return(Client.userId,
                Client.mail,
                Client.password,
                Client.contractAddress,
                Client.publickey,
                projectsNB,
                contributionsNB,
                Crowdfactory);

        }

        function getMyRewardsByContributionId(uint _id )public returns(string memory, uint){
            sharedLib.Reward memory r = myRewards[_id];
            return(r.rewardTitle, r.rewardValue );

        }


        function getMyContributionById(uint _id) public returns(string memory , uint,string memory ,uint, address, address){

            sharedLib.Contribution memory c= myContributions[_id];
            string memory rewardTitle ;
            uint  rewardValue;
            (rewardTitle, rewardValue) = getMyRewardsByContributionId( _id );
            return(c.ammount, c.tokenValue,rewardTitle, rewardValue,c.porteur,c.projet );

        }
}

and finally here is the shared lib from where I am getting my struct

pragma solidity ^0.5.0;

library sharedLib {

//-------------- Client-------------
   struct Client {
        uint userId; 
        string mail ;
        string password;
        address contractAddress;
        address publickey; //addresse de son wallet elle sera utilisé pour verifié sa signature 

   }
//-------------- contribution-------------

    struct Contribution{
          string ammount ; 
          uint tokenValue ;
          Reward chosenReward;       
          address projet;
          address contributeur ;
          address porteur; 

      } 


//-------------- Projet -------------


    //***********reward 

         struct RewardItem{
            string  itemTitle;
            uint  itemValue; // nbre de token 
             string itemDescription;
         }
         struct Reward {
             string  rewardTitle;
            RewardItem [] rewardItems;
            uint  rewardValue;

         }
     //***********etat du projet 

    enum ProjectStatus {
       Active,
       Expired,
       Closed,
       Relanced

      }
      //***********projet
    struct Projet {
        uint pID ;
        address  porteur;
        string title;
        uint montantACollect ;
        uint montantCollect;
        uint  dateDeDebut;
        uint  dateDeFin;
        address contractAddress;
        ProjectStatus stat;
        Reward [] rewards;

    }
}
  • 1
    Please format the source code. – ferit Jun 11 at 10:53
0

To run the functions on the ClientSc smart contract just call the functions on the ClientSC instance stored in usersinfo.

For example

contract CrowdFactory {    
    function executeGetInfo (uint _userId) {
       // get the clientSC instance
       ClientSc sc = usersinfo[msg.sender];
       // you can then invoke functions on sc
       var (userId, mail, password, contractAddress, publickey, ...) = sc.getMyInfo()


    }
}

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.