How to create a simple “Wallet” smart contract using Solidity ?

Paulina Lewandowska

19 Oct 2022
How to create a simple “Wallet” smart contract using Solidity ?

In the previous tutorial you learned how to create your first smart contract, in this post you will learn how to create a "Wallet" smart contract to which you will be able to send and withdraw Ethereum, of course the contract will be written so that only the owner of the contract will be able to withdraw funds.

What are the keywords: public, external, internal and private ?

You have already learned the keyword public in the previous tutorial "Hello World", it means that the function is public, that is, it can be called both "outside the contract" and inside. Contracts that inherit our contract will have access to such a function.

For example:

uint counter = 0;
    function externalFunction() external  {
        counter++;
        publicFunction();
    }
 
    function publicFunction() public  {
        counter++;
    }

As you can see, the public function can not only be called "outside the smart contract", but also inside it, as in the externalFunction, and just what does this external mean ?

If the function is external, it simply means that it can only be called "outside the smart contract" , just as we called our sayHelloWorld function in the previous tutorial. Contracts that will inherit our contract will have access to the external function.

Two keywords remain : internal and private.

function returnTwoPlusTwo() internal pure returns (uint256)  {
        return 2 + 2;
    }
 
    function returnMsgSender() private view returns (address)  {
        return msg.sender;
    }

Internal is exactly the opposite of external, such a function will not be called "outside the smart contract", but only inside. As with external and public, contracts that inherit such a function will have access to it.

The last is private which means that the function will be visible only in the contract in which it was defined, contracts that inherit our contract will not be able to call it.

Pure vs View

When I showed the functions internal and private, you can see that the words pure and view are added next to these functions. What do they mean ?

When the function is pure, it means that it does not modify or read any data from the blockchain, just like the returnTwoPlusTwo function - it only returns the result of 2+2, it does not load or modify any variable in the smartcontract or blockchain.

Functions with the suffix view, means that the function does not modify data from the blockchain, but instead reads it. For example, the returnMsgSender function reads the value of the msg.sender variable, which represents the address that called the function.

Okay, enough with the theory, let's finally get to work !

How to create "Wallet" smart contract?

First we must, as always, define the version of solidity that we want to use , I will use version 0.8.12, so at the top of the file I type:

pragma solidity 0.8.12;

I am creating a contract called Wallet :

contract Wallet {
   
}

Each wallet has its own owner so will define address on ethreum, who will be the owner of the smart contract. The owner of the smart contract will be the person who will deploy our smart contract.  And we should have a variable thanks to which we can monitor the balance of the smart contract.

contract Wallet {
    address public owner;
    uint public balance;
    constructor() {
        owner = msg.sender;
    }

Let's create a function by which we can transfer funds to the smart contract.

function depositEther() external payable{
        balance += msg.value;
    }

There are two new words in this function : payable and msg.value.

If the function is payable it means that with the function call we can send ethereum to the smart contract, and msg.value is simply the amount of wei sent with the function call.

Now let's create a function by which we can withdraw the sent ethereum, of course, only the owner of the smart contract should be able to do so.

function withdrawEther(uint amount) external{
        require(msg.sender == owner, "Only owner can call this function");
        require(amount <= balance, "Amount exceeds balance");
        balance -= amount;
        payable(owner).transfer(amount);
    }

Require makes the function return an error with the message we specified when the condition given in it fails.

In the function, we had to convert the owner variable from address to address payable, because ethereum can only be sent to addresses with the keyword payable.

Summary

And that's it ! Smart contract is ready ! Go ahead and try to play with it, and if you succeed, even improve it. 

In the next tutorial in the Nextrope Academy series, we will show how to write a simple auction smart contract.

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.