[Ethereum] How contract owner can interact with smart contract

solidityweb3js

I've created a smart contract with ERC20 standards, I am using Ethereum TestRPC, Web3js and remix along with ABI/contract address to interact with contract functions. But I have created a modifier inside contract and applied to few functions (like functions start and stop to start/stop contract any time).

Anyone can interact with my contract using above tools, but my question is how can I specify that I'm the admin/owner of contract, So I can call Start and Stop functions?

Any help would be appreciated.

Best Answer

Please don't be confuse on accessing function using web3js. According to your question..


created a modifier inside contract and applied to few functions May be you are using modifier as below (no hard and fast)


pragma solidity 0.4.22;

contract Token{

    address owneraddress;
    modifier onlyowner {
        require(owneraddress == msg.sender);
        _;
    }

    function Token(){
        owneraddress = msg.sender ;
    }

    function start() onlyowner {
      //your logic here  
    }

    function stop() onlyowner {
     //your logic here
    }
}

This restrict to other address except owner . Here owner is assigned as address by which the contract is deployed, Because here constructor is called once when contract is deployed. so you don't need to worry about any other can access this function except owner address.

Now the case is, If you give contract code and contract address to any one then also other account cannot access this function.

Any one can make there own Interface and access these function and again the result will be same. So this conclude that you do not need to restrict through web3js API.

If you want to specify in web3js part that you are the owner and only you want to access those own able function then there is no worth of giving your contract address and code to anyone, They will use there way so you don't have any control on it. If you are making Dapp and other user use your dapp then you can do in web3js layer. And this can be done as :-

web3.DeployedContractRef.start( { from: owneraddress});

web3.DeployedContractRef.stop( { from: owneraddress});

It might help you !

Related Topic