How do I give access to only owner to call the function? As when I try this code owner is not able to access or else both owner as well as others are able to access the function.

modifier _ownerOnly(){

require(msg.sender == owner); _;


function getAllUsers()public view _ownerOnly returns (address[], string[], string[], string[], string[]){

    address[] memory wallet_addresses = new address[](registeredArray.length);
    string[]  memory _ids = new string[](registeredArray.length);
    string[] memory firstNames = new string[](registeredArray.length);
    string[] memory lastNames = new string[](registeredArray.length);
    string[] memory emailIds = new string[](registeredArray.length);
    for (uint i = 0; i < registeredArray.length; i++) {
        wallet_addresses[i] = registeredArray[i].wallet_address;
        _ids[i] = registeredArray[i].userId;
        firstNames[i] = registeredArray[i].first_name;
        lastNames[i] = registeredArray[i].last_name;
        emailIds[i] = registeredArray[i].email_id;
    return (wallet_addresses, _ids, firstNames, lastNames, emailIds);

1 Answer 1


You have to use the modifier on your function like so.

address owner;

 modifier onlyOwner() {
    require(msg.sender == owner);

constructor(address _owner){
owner = _owner;

function MyOwnedFunction(address arg1, uint arg2) public onlyOwner {
  // do things only Owner can do here

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.