How to create a simple smart contract to manage auctions ?

Paulina Lewandowska

07 Dec 2022
How to create a simple smart contract to manage auctions ?

In the previous tutorial you learned how to create a smart contract, which is a wallet. In this tutorial we will try to consolidate the knowledge from the previous tutorial, and expand it with new knowledge. 

So let's get to work. All the things you may not understand will be explained to you later in the text.

Defining variables

Let's start by defining the variables we'll need to make the smart contract work. We certainly need :

  • address of the person to whom the highest bid will be sent,
  • time when the auction in question will end,
  • address of the person who placed the highest bid,
  • why wei is the highest bid,
  • a table of addresses and the amount of money they transferred to the smart contract so that those who did not win the auction can withdraw their money,
  • variable whether the auction is completed or not.
pragma solidity 0.8.11;

contract Auction {

    address payable public beneficiary;

    uint public auctionEndTime;

    address public highestBidder;

    uint public highestBid;

    mapping(address => uint) pendingReturns;

    bool ended;

}

What can you not understand from the above code?

Mapping in solidity is a key-value array, equivalent to dictionary in other languages.

If you don't know why the auctionEndTime variable is given in plain uinta, it's because the time when the auction ends will be given in Unix time.

Let's create a constructor that will take the address to which the highest bid will be sent and how long the auction will last.

constructor(

        uint biddingTime,

        address payable beneficiaryAddress

    ) {

        beneficiary = beneficiaryAddress;

        auctionEndTime = block.timestamp + biddingTime;

    }

What is worth paying attention to ?

  • block.timestamp is a variable that simply means what time it is now given as Unix time of course ;)))

Function for making an offer

Now let's create a function that will be used to submit your bid. The function will return an error if :

  • The auction has ended
  • Our bid will be lower than the highest bid

At the end of the function execution, the function will emit an event that the highest bid has changed. The frontend application can listen to the emitted events on the smartcontest, so that as soon as the highest bid has changed, it can update it in the user interface.

event HighestBidIncreased(address bidder, uint amount);

    event AuctionEnded(address winner, uint amount);

    error AuctionAlreadyEnded();

    error BidNotHighEnough(uint highestBid);

    error AuctionNotYetEnded();

    error AuctionEndAlreadyCalled();

    function bid() external payable {

        if (block.timestamp > auctionEndTime)

            revert AuctionAlreadyEnded();

        if (msg.value <= highestBid)

            revert BidNotHighEnough(highestBid);

        if (highestBid != 0) {

            pendingReturns[highestBidder] += highestBid;

        }

        highestBidder = msg.sender;

        highestBid = msg.value;

        emit HighestBidIncreased(msg.sender, msg.value);

    }

As you can see in the code above, we define ourselves events with parameters that we can emit on the blockchain. To emit an event in solidity we type 

emit + event name and parameters

We have defined our own errors, which if we want to call them we type in revert + the name of our errror and parameters.

You have probably already guessed that instead of ifs and custom errors we could have used requier.

This function checks if the auction has already ended, if msg.value is higher than the highest bid, if so we update the mapping pendingReturns so that the person who placed the highest bid earlier can get his money back. We assign the highest bid to msg.value and the highestBidder to msg.sender, at the end of the function execution we emit an event that informs that the highest bid has been increased.

Function to end the auction, and transfer the highest bid to the benefactor

Now let's create a function so that after the auction ends, the beneficiary's address can send money to his wallet.

This function should:

  • Return an error if the auction has not yet ended,
  • return an error if this function has already been called,
  • change the ended variable to true,
  • emit an event indicating that the auction has ended,
  • transfer an amount of Ethereum equivalent to the highest bid to the benefactor.
function auctionEnd() external {

        if (block.timestamp < auctionEndTime)

            revert AuctionNotYetEnded();

        if (ended)

            revert AuctionEndAlreadyCalled();

        ended = true;

        emit AuctionEnded(highestBidder, highestBid);

        beneficiary.transfer(highestBid);

    }

Function for people who did not win the auction and want their money back

Now, the last function we need to make our contract ready! It will be for addresses that did not win the auction and want to get their money back. Let's consider what such a function should have in it :

  • it should check how much Ethereum you owe in the mapping pendingReturns and assign this value to a variable,
  • it should change how much you owe to 0,
  • it should send as much Ethereum as you have stored in the variable.

Well, let's get to work !

  function withdraw() external{

        uint amount = pendingReturns[msg.sender];

        pendingReturns[msg.sender] = 0;

        payable(msg.sender).transfer(amount);

    }

That's the end of today's tutorial ! Our smart contract is ready. In order to practice and consolidate your knowledge, as a task you can try to replace custom errors with requirs. However, if this is not enough for you, you can also improve this contract so that it can be used to conduct several auctions at once.

Tagi

Most viewed


Never miss a story

Stay updated about Nextrope news as it happens.

You are subscribed

How NOT to Create a DAO: Common Pitfalls You Should Avoid

Kajetan Olas

27 Dec 2024
How NOT to Create a DAO: Common Pitfalls You Should Avoid

Decentralized Autonomous Organizations (DAOs) represent a fundamental shift in how communities, companies, and initiatives can coordinate efforts, funds, and decisions on the blockchain. By leveraging transparent smart contracts and on-chain governance mechanisms, DAOs aim to distribute authority, reduce overhead, and foster a more democratic decision-making process. However, building a successful DAO isn’t just about cutting-edge tech or grand ideas—it also requires a clear vision, well-crafted governance rules, and a strategically engaged community.

In this article, we’ll take a counterintuitive approach by highlighting how not to create a DAO. By focusing on common pitfalls—from legal oversights to governance missteps—we can better understand what truly contributes to a thriving, sustainable DAO. This perspective aligns with the importance of recognizing cognitive biases, such as insensitivity to base rates and the conjunction fallacy, which often lead enthusiastic founders to overlook real-world data and complexity. Avoiding these traps can be the difference between launching a resilient DAO and watching an ambitious project crumble under misaligned structures or unmet expectations.

2. Missing the Governance Threshold Mark

Governance Thresholds Gone Wrong

Governance thresholds dictate how many votes or what percentage of voting power is needed to pass a proposal within a DAO. Striking the right balance here is crucial. Thresholds that are set too high can stifle progress by making it nearly impossible for proposals to succeed, effectively discouraging member participation. On the other hand, thresholds that are too low can lead to frivolous proposals or constant voting spam, making governance more of a burden than a benefit.

When designing your DAO’s thresholds, consider:

  • Community size and engagement levels: Larger communities might handle higher thresholds more comfortably, while smaller groups may benefit from lower requirements to encourage active participation.
  • Type of proposals: Operational decisions may need a lower threshold, whereas critical changes (such as tokenomics or treasury management) often require more consensus.
  • Voter fatigue: The more frequently members are asked to vote—and if it’s too easy to put forward proposals—the greater the risk of apathy or disengagement.

Over-Complex vs. Over-Simplified Governance

It’s tempting to either pile on complicated governance rules or oversimplify them to keep decision-making quick. However, both extremes can be problematic. Simplicity in governance is key to enhancing clarity and participation. Overly complex smart contracts and procedural layers can dissuade newcomers from getting involved, while an oversimplified model might fail to address potential conflicts or security vulnerabilities.

Some issues to watch out for:

  • Complex Smart Contracts: More code means more potential bugs and greater difficulty in auditing or updating governance logic.
  • Opaque Voting Processes: If members can’t easily understand how votes are tallied or how proposals are introduced, engagement drops.
  • Excessive Centralization in “Simple” Models: In trying to streamline governance, some DAOs inadvertently concentrate power in the hands of a few decision-makers.

Ultimately, aiming for a balanced governance framework—one that is easy enough for members to participate in but comprehensive enough to protect the DAO from abuse—is central to avoiding the pitfalls of governance threshold mismanagement.

3. Underestimating Legal and Regulatory Aspects

Legal Wrappers and Compliance

Building a DAO without considering legal and regulatory frameworks is a common recipe for disaster. While decentralization is a powerful concept, it doesn’t absolve projects from potential liabilities and compliance obligations. Assigning your DAO a formal legal wrapper—whether it’s a foundation, a cooperative, an LLC, or another entity type—can help mitigate personal risks for contributors and align your organization with existing regulatory regimes.

Failing to think through these details often leads to:

  • Personal Liability for Founders: Without a proper legal entity, core contributors might become personally responsible for any legal disputes or financial mishaps involving the DAO.
  • Regulatory Crackdowns: Governing bodies worldwide are actively monitoring DAOs for compliance with securities laws, anti-money laundering (AML) regulations, and tax obligations. Ignoring these can lead to penalties, fines, or forced shutdowns.

Non-Existent or Inadequate Documentation

Equally problematic is the lack of clear documentation outlining the DAO’s legal structure and operational protocols. From voting procedures to treasury management, every aspect of the DAO’s lifecycle should be properly documented to reduce ambiguity and help new members understand their responsibilities. Inadequate documentation or outright neglect can create:

  • Confusion Over Roles and Responsibilities: Without explicit definitions, it’s easy for tasks to fall through the cracks or for disagreements to escalate.
  • Inability to Enforce Rules: DAOs rely on both smart contracts and social consensus. Formalizing rules in documentation helps ensure consistent enforcement and prevents unwelcome surprises.

In short, underestimating the legal dimension of DAO creation can derail even the most innovative projects. By proactively addressing legal and regulatory considerations—and maintaining thorough documentation—you not only protect core contributors but also fortify trust within your community and with external stakeholders.

Overlooking Community Building

The Importance of Community Engagement

A DAO, at its core, is nothing without an active and supportive community. Driving grassroots enthusiasm and participation is often the deciding factor between a thriving DAO and one that fizzles out. Yet, it’s surprisingly easy to underestimate just how vital it is to nurture community trust and engagement—especially during the early stages.

Some common pitfalls include:

  • Treating Community Members as Passive Observers
    Instead of viewing your community as a dynamic force, you might slip into a one-way communication style. This discourages members from taking initiative or contributing fresh ideas.
  • Lack of Clear Roles and Channels
    Without well-defined roles and open communication channels—like forums, Discord servers, or governance platforms—members can feel confused about where to participate or how to add value.
  • Ignoring Early Feedback
    In a DAO, the “wisdom of the crowd” can be a powerful asset. Overlooking or trivializing user feedback can lead to missed opportunities for innovation and improvement.

Failing to Incentivize Properly

Well-structured incentives lie at the heart of any successful DAO. Whether you’re offering governance tokens, staking rewards, or recognition badges, these incentives must be aligned with the DAO’s long-term goals. Misalignment often causes short-sighted behavior, where participants chase quick rewards rather than contributing meaningfully.

  • Overemphasis on Token Speculation
    If the primary draw for community members is the promise of quick token price gains, you risk attracting speculators instead of builders. This can lead to fleeting participation and sell-offs at the first sign of trouble.
  • Neglecting Non-Monetary Rewards
    Recognition, social standing, and meaningful collaboration can be just as powerful as financial incentives. When a DAO fails to provide pathways for skill development or leadership, member engagement wanes.
  • Cognitive Bias Traps
    Biases such as the conjunction fallacy can mislead founders into believing that if multiple positive outcomes are possible (e.g., rising token prices, active participation, mainstream adoption), then all those outcomes will inevitably happen together. This wishful thinking can blind DAOs to the need for thoughtful, data-driven incentive models.

To avoid these pitfalls, DAO creators must actively foster a culture of transparency, collaboration, and mutual respect. By setting clear expectations, leveraging diverse incentive structures, and consistently involving community feedback, you ensure members are motivated to contribute more than just their votes—they become co-creators in the DAO’s shared vision.

5. Ignoring Technical Considerations

Token Standards and Governance Frameworks

A solid technical foundation is essential when you create a DAO, particularly if it involves on-chain governance. Selecting the appropriate token standards and governance frameworks can significantly impact your DAO’s security, efficiency, and scalability.

Some pitfalls to watch out for include:

  • Choosing Incompatible Token Standards
    If your DAO relies on a token that isn’t easily integrated with governance contracts or lacks upgradeability, you might face roadblocks when implementing new features or patching vulnerabilities.
  • Underestimating Smart Contract Complexity
    Even “simple” governance tokens can hide complex logic behind the scenes. Overlooking these complexities may result in bugs, lockouts, or exploits that harm the DAO’s reputation and finances.
  • Ignoring Off-Chain vs. On-Chain Dynamics
    Governance strategies often combine on-chain decisions with off-chain discussions (e.g., using platforms like Discord or forums). Failing to synchronize these two spheres can fracture community engagement and hamper decision-making.

Poor Architecture and Security

Robust security isn’t just about preventing hacks—it's about building an architecture that can adapt to evolving threats and changing community needs.

Key oversights include:

  • Inadequate Auditing
    Smart contracts require thorough reviews, both automated and manual. Rushing to mainnet deployment without proper audits can lead to major losses—financial, reputational, or both.
  • No Contingency Plans
    If a vulnerability is discovered, how will you respond? Lacking emergency procedures or fallback governance mechanisms can leave a DAO paralyzed when critical decisions must be made quickly.
  • Over-Engineered Solutions
    While security is paramount, over-complicating the DAO’s architecture can create unintended vulnerabilities. Keeping your setup as simple as possible reduces attack surfaces and makes it easier for community members to understand and trust the system.

In short, technical considerations form the bedrock of a functional DAO. Choosing appropriate token standards, thoroughly auditing contracts, and designing for both present-day and future needs are non-negotiable steps in avoiding costly pitfalls.

Best Practices and Lessons

When studying successful DAOs, certain themes emerge time and again. According to Aragon the most robust DAOs share a commitment to simplicity, iteration, and transparent governance. Instead of rolling out overly sophisticated models from day one, they evolve and adapt based on community feedback and real-world performance.

Here are a few best practices worth emulating:

  • Iterative Approach to Governance
    Start small and build up. Launch a Minimal Viable DAO (MVD) to test voting processes, incentive mechanisms, and proposal management. Gather community feedback and refine before taking bigger steps.
  • Simple, Transparent Rules and Processes
    Ensure proposals are easy to understand and that the voting process is accessible to all token holders. Overly complicated frameworks can dissuade new members from participating.
  • Clear Roles and Shared Responsibilities
    Define contributor and community member roles early on. Whether you rely on working groups, committees, or elected leaders, clarity prevents power vacuums and fosters collaboration.
  • Open Communication and Education
    From Discord channels to public documentation, keep conversation and learning at the heart of your DAO. Encourage members to ask questions, propose improvements, and take leadership roles.

Academic Perspectives

Beyond practical experience, a growing body of research offers theoretical insights that can strengthen DAO governance. The discusses emerging patterns in DAOs, including how incentives and on-chain rules interact with off-chain social dynamics. By examining these findings, DAO creators can better anticipate challenges—like voter apathy, whale influence, or collusion—and integrate solutions from the outset.

Incorporating academic perspectives can help:

  • Validate Governance Assumptions
    Empirical data and rigorous analyses can confirm or challenge the assumptions behind your DAO’s architecture, preventing costly mistakes.
  • Stay Ahead of Regulatory and Social Shifts
    Academics often explore how upcoming policies or societal trends might impact DAOs, offering a forward-looking lens that day-to-day builders might miss.
  • Establish Credibility
    Aligning your DAO’s structure and operations with recognized research signals professionalism and thoroughness, potentially attracting more serious contributors, partners, and investors.

Conclusion

As you can see, creating a DAO involves more than just deploying a smart contract and distributing tokens. By examining these common pitfalls—from poor governance thresholds to inadequate legal structures, from neglecting community engagement to disregarding technical complexities—you gain a clearer picture of what not to do when you set out to create a DAO. Failing to address these areas often leads to compromised security, stalled decision-making, regulatory headaches, or outright community collapse

At Nextrope, we specialize in tailored blockchain and cryptocurrency solutions, including DAO creation and tokenomics design. If you’re looking to avoid these common pitfalls and build a thriving DAO that stands the test of time, feel free to contact us or explore more resources on our blog.

Quadratic Voting in Web3

Kajetan Olas

04 Dec 2024
Quadratic Voting in Web3

Decentralized systems are reshaping how we interact, conduct transactions, and govern online communities. As Web3 continues to advance, the necessity for effective and fair voting mechanisms becomes apparent. Traditional voting systems, such as the one-token-one-vote model, often fall short in capturing the intensity of individual preferences, which can result in centralization. Quadratic Voting (QV) addresses this challenge by enabling individuals to express not only their choices but also the strength of their preferences.

In QV, voters are allocated a budget of credits that they can spend to cast votes on various issues. The cost of casting multiple votes on a single issue increases quadratically, meaning that each additional vote costs more than the last. This system allows for a more precise expression of preferences, as individuals can invest more heavily in issues they care deeply about while conserving credits on matters of lesser importance.

Understanding Quadratic Voting

Quadratic Voting (QV) is a voting system designed to capture not only the choices of individuals but also the strength of their preferences. In most DAO voting mechanisms, each person typically has one vote per token, which limits the ability to express how strongly they feel about a particular matter. Furthermore, QV limits the power of whales and founding team who typically have large token allocations. These problems are adressed by making the cost of each additional vote increase quadratically.

In QV, each voter is given a budget of credits or tokens that they can spend to cast votes on various issues. The key principle is that the cost to cast n votes on a single issue is proportional to the square of n. This quadratic cost function ensures that while voters can express stronger preferences, doing so requires a disproportionately higher expenditure of their voting credits. This mechanism discourages voters from concentrating all their influence on a single issue unless they feel very strongly about it. In the context of DAOs, it means that large holders will have a hard-time pushing through with a proposal if they'll try to do it on their own.

Practical Example

Consider a voter who has been allocated 25 voting credits to spend on several proposals. The voter has varying degrees of interest in three proposals: Proposal A, Proposal B, and Proposal C.

  • Proposal A: High interest.
  • Proposal B: Moderate interest.
  • Proposal C: Low interest.

The voter might allocate their credits as follows:

Proposal A:

  • Votes cast: 3
  • Cost: 9 delegated tokens

Proposal B:

  • Votes cast: 2
  • Cost: 4 delegated tokens

Proposal C:

  • Votes cast: 1
  • Cost: 1 delegated token

Total delegated tokens: 14
Remaining tokens: 11

With the remaining tokens, the voter can choose to allocate additional votes to the proposals based on their preferences or save for future proposals. If they feel particularly strong about Proposal A, they might decide to cast one more vote:

Additional vote on Proposal A:

  • New total votes: 4
  • New cost: 16 delegated tokens
  • Additional cost: 16−9 = 7 delegated tokens

Updated total delegated tokens: 14+7 = 21

Updated remaining tokens: 25−21 = 425 - 21 = 4

This additional vote on Proposal A costs 7 credits, significantly more than the previous vote, illustrating how the quadratic cost discourages excessive influence on a single issue without strong conviction.

Benefits of Implementing Quadratic Voting

Key Characteristics of the Quadratic Cost Function

  • Marginal Cost Increases Linearly: The marginal cost of each additional vote increases linearly. The cost difference between casting n and n−1 votes is 2n−1.
  • Total Cost Increases Quadratically: The total cost to cast multiple votes rises steeply, discouraging voters from concentrating too many votes on a single issue without significant reason.
  • Promotes Egalitarian Voting: Small voters are encouraged to participate, because relatively they have a much higher impact.

Advantages Over Traditional Voting Systems

Quadratic Voting offers several benefits compared to traditional one-person-one-vote systems:

  • Captures Preference Intensity: By allowing voters to express how strongly they feel about an issue, QV leads to outcomes that better reflect the collective welfare.
  • Reduces Majority Domination: The quadratic cost makes it costly for majority groups to overpower minority interests on every issue.
  • Encourages Honest Voting: Voters are incentivized to allocate votes in proportion to their true preferences, reducing manipulation.

By understanding the foundation of Quadratic Voting, stakeholders in Web3 communities can appreciate how this system supports more representative governance.

Conclusion

Quadratic voting is a novel voting system that may be used within DAOs to foster decentralization. The key idea is to make the cost of voting on a certain issue increase quadratically. The leading player that makes use of this mechanism is Optimism. If you're pondering about the design of your DAO, we highly recommend taking a look at their research on quadratic funding.

If you're looking to create a robust governance model and go through institutional-grade testing please reach out to contact@nextrope.com. Our team is ready to help you with the token engineering process and ensure that your DAO will stand out as a beacon of innovation and resilience in the long term.