Say I have a contract with the address and method below.


Can everyone who knows this address call this smart contract method? Any permissions restrictions?

1 Answer 1


It depends how you write the contract.

You get the access control you design. There are more intricate access control patterns such as whitelists, but to lay out a simple example that is admittedly flawed, but hopefully illustrative:

  contract Greeter {

  address public owner; 

  function Greeter() public {
    owner = msg.sender; // <= the "owner" will be set to the account that deployed it. 

  function greet() public view returns(string greeting) {
    require(msg.sender == owner); // only the priviledged account will pass
    return "Hello, owner.";

Hope it helps.

  • It sure does Rob! Much thanks! Can a smart contract have multiple owners too? Or just one?
    – Nathan Aw
    Commented Apr 6, 2018 at 5:17
  • It's all up to you. There can be only one creator (who is called 'owner' in the above code) but your code can allow extended access to any number of addresses. You'd need to have a function (which is accessible only for the first owner) with which new owners can be added. Commented Apr 6, 2018 at 5:55
  • Why did you specify the name greeting for the return string if it isn't used? I've seen this done before and I don't really understand the benefit of it. Commented Jun 8, 2018 at 1:53
  • It's not "used" in the sense that there a conflict with another contract. It's a just a simple example for the topic at hand. Each contract has its own storage space and there is no need to worry that, say "x" is used by something else elsewhere on the chain. In case it's unclear, the contracts share the same chain, but each contract has its own logical storage space. There are physical implementation details that can confuse the matter but I think this summary will serve you well for now. Commented Jun 8, 2018 at 6:11

Your Answer

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

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