0

I have a Reputation contract which has a function foo() that sets some point.

In another contract called Market I want to use the foo() function. But I don't want any one to be able to call foo() outside Market.

the problem is I need to deploy Reputation first and make instance of it in market. I have no idea how to make modifier in Reputation to restrict foo() before deploying Market.

1 Answer 1

1

Check msg.sender and reject unacceptable actors.

In Market to protect foo() - make sure msg.sender == reputation.

Also in Market - a function to update reputation when you know the address.

Here's a little scribble to give you some ideas.

contract Market {

  address reputation;

  modifier onlyReputation {
    require(msg.sender == reputation, "403");
    _;
  }

  constructor(address reputation_) {
    reputation = reputation_;
  }

  function foo() public onlyReputation {
    // carry on
  }
}

That is the general idea. You can add functions to edit/update the acceptable reputation from time to time. You would want another variable, e.g. address owner to specify who is allowed to do that.

Finally, if you want to coordinate the deployment and there is one Market for each Reputation, use the constructors to configure everything on the fly.

In Reputation:

Market market;);

constructor () {
   market = new Market();
}

That way it will create one and know where it is. In Market, recognize "the creator" as the one to trust.

address reputation;

constructor () {
  reputation = msg.sender;
}

Hope it helps.

1
  • this is the opposite of what I was looking for. I needed a modifier called onlyMarket. But thanks, your answer gave me the idea how to do that. All I wanted to need was to initiate market with some address and then update the market address in reputation contract using some other functions. :)
    – Amin
    Mar 9, 2021 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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