Rise In Logo



Learn everything about Solidity

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?

Comments

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!

Disclaimer: The information /programs / events provided on https://patika.dev and https://risein.com are strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice and do not make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://patika.dev and https://risein.com disclaim any responsibility for financial decisions made by users based on information provided here.