Start using GovernChecker

Implementing onlyAuthorizedToGovern

If a dApp wants to configure an automatic action based on proposal voting, it has to give authority to the dApp voting contract to execute the specified function call. The following steps need to followed for this:

1) Start by registering your dApp on

2) Download Governed.sol for importing into your contracts.

3) Open the Governed.sol and edit the constructor to set your registered dApp name like this

constructor() public {
dappname =REGISTERED-DAPP-NAME; //change here

4) Import Governed.sol in your contracts using the import statement.

import "./Governed.sol";

5) Inherit the Governedcontract in your contracts just like you inherit Ownablecontract.

contract MySecureContract is Governed {
//contract code

6) Use onlyAuthorizedToGovernmodifier to make the functions secure (replace the onlyOwnermodifier with onlyAuthorizedToGovern).

function secureFunction() public onlyAuthorizedToGovern {
//critical stuff

7) Test it out on the GovBlocks platform by creating a category that is supposed to call your contract’s function and then creating a proposal and accepting it.

How does it work?

When you register your application on GovBlocks platform, your dApp’s SimpleVoting address is given the permission to execute commands in the network wide GovernChecker. The authorized addresses are storing in a mapping of an Array.

mapping (bytes32 => address[]) public authorized;

The first address is added by the master contract of your dApp. Master can only add the first authorized address using initializeAuthorized

function initializeAuthorized(bytes32 _dAppName, address _authorizedAddress)
require(authorized[_dAppName].length == 0);
if (address(govBlockMaster) != address(0))
require(govBlockMaster.getDappMasterAddress(_dAppName) == msg.sender);

Only the already authorized addresses can add more authorized addresses. SimpleVoting is the first authorized address and it can add more when a vote is passed for it. Every Authorized address can pass on (only) its authorization to someone else or renounce it by setting it to address(0).

The Governed.sol you inherit has hard-coded address of the official GovernChecker contracts.

Whenever onlyAuthorizedToGovern modifier is used, it calls the GovernChecker contract to verify that the msg.sender is authorized by the dApp.

modifier onlyAuthorizedToGovern() {
if (address(governChecker) != address(0))
require(governChecker.authorizedAddressNumber(dappName, msg.sender) > 0);