Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Intelligent contract of DAO shareholders' Association in Ethernet Square

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

< p.votes.length; ++i) { Vote storage v = p.votes[i]; uint voteWeight = sharesTokenAddress.balanceOf(v.voter); quorum += voteWeight; if (v.inSupport) { yea += voteWeight; } else { nay += voteWeight; } } require(quorum >

= minimumQuorum); / / Check if a minimum quorum has been reached if (yea > nay) {/ / Proposal passed; execute the transaction p.executed = true; (bool success,) = p.recipient.call.value (p.amount) (transactionBytecode); require (success); p.proposalPassed = true } else {/ / Proposal failed p.proposalPassed = false;} / / Fire Events emit ProposalTallied (proposalNumber, yea-nay, quorum, p.proposalPassed);} deployment and use

The deployment of the code is almost exactly the same as the previous code, but you also need to place a shared token address shares token address, which is the token address, which will be used as a voting share.

Note these lines of code: first, let's describe the token contract for the new contract. Since it only uses the balanceOf function, we only need to add that line.

Contract Token {mapping (address = > uint256) public balanceOf;}

Then we define a variable with a type tag, which means that it will inherit all the functions we described earlier. Finally, we point the token variable to the address on the block chain, so it can use it and request real-time information. This is the easiest way to make one contract understand another in Ethernet Square.

Contract Association {token public sharesTokenAddress;//... constructor (token sharesAddress, uint minimumSharesForVoting, uint minutesForDebate) {sharesTokenAddress = token (sharesAddress)

The association association posed a challenge that the previous conference congress did not have: because anyone with a token can vote and the balance can change quickly, the actual score of the proposal cannot be calculated when shareholders vote, otherwise someone can vote multiple times by simply sending his share to a different address. Therefore, in this contract, only the voting position is recorded, and then the actual score is calculated during the implementation phase of the proposal.

Uint quorum = 0quorum uint yea = 0poliuint nay = 0quorum (uint I = 0; I < p.votes.sessions; + + I) {Vote v = p.votes [I]; uint voteWeight = sharesTokenAddress.balanceOf (v.voter); quorum + = voteWeight; if (v.inSupport) {yea + = voteWeight;} else {nay + = voteWeight;}}

Another way to calculate weighted voting is to create a single signed integer to keep the vote score and check whether the result is positive or negative, but you must use int to convert an unsigned integer voteWeight to a signed integer score = int (voteWeight)

Use this DAO as before: members create new proposals, vote on them, wait until the deadline is over, and then anyone can calculate the vote and execute it.

But how do I limit the owner's power?

In this contract, the address set as owner owner has some special powers: they can add or prohibit members at will, change the margin required to win, change the time required for debate, and the quorum needed to vote. But this can be solved by using another kind of power owned by the owner: change of ownership.

The owner can change ownership to anyone by pointing the new owner to 0x00000. This will ensure that the rules will never change, but this is an irreversible action. The owner can also change the ownership to the contract itself: simply click the copy address copy address and add it to the new owner new owner field. This will allow all the rights of the owner to be enforced by creating a proposal.

If you like, you can also set up a contract as the owner of another contract: suppose you want a company structure, you want a lifelong president with the power to appoint board members, and then you can issue more shares. in the end, these stocks are voted on how to spend the budget. You can create an associated contract Association that uses the mintable token owned by the conference congress that is ultimately owned by a single account.

But what if you want different voting rules? Maybe you need 80% consensus to change the voting rules, or the members may be different. In this case, you can create another same DAO or use some other source code and insert it as the first owner.

At this point, I believe you have a deeper understanding of "how to realize the intelligent contract of DAO shareholders Association in Ethernet Square". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report