Rise In Logo

Solidity Fundamentals

So far, you added the Proposalstruct, a mapping and a function to create ProposalCurrently anyone can create a Proposal in our contract. What we want is that only the owner of this contract can create new proposals.

To achieve that, first you need to add a new line to the beginning of our contract.

address owner;

You have created a new variable named ownerwhich will be representing the owner of the contract.

Now that you have the necessary variable for the owner, we need set the owner.

The best place to set the owner of the contract inside the constructor.

Constructor runs once when you first deploy our contract. Here we want to set owner of the contrat to the address that has deployed the contract.

You can have the address that made the transaction with: msg.sender

constructor() {
  owner = msg.sender;

Now you have the owner but how can we use this owner in the function so that the only owner of the contract can use the function?

Rise In Logo

Rise together in web3