<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: PRINCE EGBEDELE</title>
    <description>The latest articles on DEV Community by PRINCE EGBEDELE (@prince_eniola).</description>
    <link>https://dev.to/prince_eniola</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1843174%2Fd7112dd4-80c9-4e2d-9e0a-d67df65d70ee.jpg</url>
      <title>DEV Community: PRINCE EGBEDELE</title>
      <link>https://dev.to/prince_eniola</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prince_eniola"/>
    <language>en</language>
    <item>
      <title>Navigating the crowd funding smart contract workflow in an open financial network - stellar</title>
      <dc:creator>PRINCE EGBEDELE</dc:creator>
      <pubDate>Mon, 19 Aug 2024 03:40:08 +0000</pubDate>
      <link>https://dev.to/prince_eniola/navigating-the-crowd-funding-smart-contract-workflow-in-an-open-financial-network-stellar-41bp</link>
      <guid>https://dev.to/prince_eniola/navigating-the-crowd-funding-smart-contract-workflow-in-an-open-financial-network-stellar-41bp</guid>
      <description>&lt;p&gt;*This is a submission for the &lt;a href="https://dev.to/prince_eniola/navigating-a-crowd-funding-smart-contract-workflow-in-an-open-financial-network-stellar-1l2b"&gt;Build Better on Stellar: Smart Contract Challenge &lt;/a&gt;: &lt;/p&gt;

&lt;h2&gt;
  
  
  Your Tutorial
&lt;/h2&gt;

&lt;p&gt;This Tutorial titled Navigating a Crowd Funding Smart contract in an open financial network provides a comprehensive guide on the workflows of a Crowd funding smart contract explaining how to create a campaign, pledge a token. This tutorial also provides a brief overview  of Stellar’s Ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Created
&lt;/h2&gt;

&lt;p&gt;How It Supports the Stellar Developer Experience&lt;/p&gt;

&lt;p&gt;This tutorial supports the stellar developers experience by simplyfying the building of a crowdfunding smart contract for new developers , Ethereum developers and rust devs, with the detailed insights and practical examples of the workflow. &lt;br&gt;
New developers can easily follow through and&lt;/p&gt;

&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;My journey began with a deep curiosity about the potential of cross-border payments within Stellar’s ecosystem. I was intrigued by how this technology could be harnessed for the greater good, and this curiosity eventually led to the idea of crowdfunding. I wanted to explore how Stellar could be used not just as a tool for transactions, but as a means to impact others positively.&lt;/p&gt;

&lt;p&gt;Through my research, I gained valuable insights into Stellar’s mission and its evolution. Understanding how Stellar came to be made me realize a significant gap: developers often struggle with the workflow of what they want to build. This realization drove me to focus on creating content that clearly explains the workflow of crowdfunding on Stellar, ensuring that developers can approach their projects with confidence and clarity.&lt;/p&gt;

&lt;p&gt;One of the most rewarding aspects of this journey was working alongside my teammate. Collaborating on this project allowed us to share ideas within an innovative and engaging ecosystem, combining our strengths to create something meaningful together. This partnership was a highlight of the experience, reinforcing the value of teamwork in navigating the complexities of the Stellar network.&lt;/p&gt;

&lt;p&gt;Team members &lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/jesdi"&gt;@jesdi&lt;/a&gt; &lt;a class="mentioned-user" href="https://dev.to/prince_eniola"&gt;@prince_eniola&lt;/a&gt; &lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>stellarchallenge</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Navigating a crowd funding smart contract workflow in an open financial network - STELLAR</title>
      <dc:creator>PRINCE EGBEDELE</dc:creator>
      <pubDate>Mon, 19 Aug 2024 03:05:51 +0000</pubDate>
      <link>https://dev.to/prince_eniola/navigating-a-crowd-funding-smart-contract-workflow-in-an-open-financial-network-stellar-1l2b</link>
      <guid>https://dev.to/prince_eniola/navigating-a-crowd-funding-smart-contract-workflow-in-an-open-financial-network-stellar-1l2b</guid>
      <description>&lt;h2&gt;
  
  
  The Stellar Ecosystem
&lt;/h2&gt;

&lt;p&gt;For those new to the Stellar universe; welcome aboard! This train is headed toward deeply understanding one of the most innovative blockchain ecosystems. And for our seasoned travelers who have mastered the tracks, feel free to teleport straight to our last stop, where we’ll embark on the adventure of the work of a crowdfunding smart contract with Soroban. &lt;/p&gt;

&lt;p&gt;Have you ever heard of an open network designed for securely storing and transferring money while onboarding boundless innovation? A world where cross-border payments are as effortless as sending a message?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fweermgtw2jelv2yon4fh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fweermgtw2jelv2yon4fh.png" alt="stellar" width="512" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our First Stop: What Is Stellar?&lt;br&gt;
Stellar is a layer 1 decentralized, open-source blockchain ecosystem designed to improve traditional financial systems, making money better. It bridges the cryptocurrency world and conventional finance, enabling fast, efficient, and cost-effective cross-border payments. It also allows the creation of digital representations of value, such as fiat currencies and custom-made currencies.&lt;/p&gt;
&lt;h2&gt;
  
  
  WHO ARE THE VISIONARIES BEHIND STELLAR?
&lt;/h2&gt;
&lt;h5&gt;
  
  
  THE FOUNDING STORY
&lt;/h5&gt;

&lt;p&gt;Unlike other ecosystems, these visionaries had an unwavering singular focus; the seamless transfer of value. In 2014, two cryptocurrency OG’s laid the foundation for Stellar, Jed McCaleb and Joyce Kim. Jed McCaleb is an experienced entrepreneur known for founding Mt. Gox and co-founding Ripple. Joyce Kim, on the other hand, is a former lawyer and venture capitalist who established the Stellar Development Foundation.&lt;/p&gt;

&lt;p&gt;The journey began with a pivotal conversation between McCaleb and Patrick Collison, co-founder of Stripe. They discovered a shared alignment in their goals and values, particularly the potential to create a more inclusive financial system. Recognizing the transformative potential of Stellar, Stripe invested $3 million into the project, providing critical early support alongside Silicon Valley legends Keith Radios (ex-PayPal exec), Sam Altman (OpenAI and Worldcoin founder), and Naval Ravikant (AngelList). This investment wasn’t just a financial boost, it was a validation of Stellar’s potential to reshape the financial landscape.&lt;/p&gt;
&lt;h2&gt;
  
  
  PROBLEMS WITH PAYMENTS
&lt;/h2&gt;

&lt;p&gt;One of the biggest challenges in traditional banking is fragmentation, which refers to the lack of cooperation among various financial institutions and services. This fragmentation makes it increasingly difficult to send money to individuals in different parts of the world.&lt;/p&gt;

&lt;p&gt;Several factors contribute to this issue:&lt;/p&gt;

&lt;p&gt;Diverse Technologies and Platforms: The financial industry is riddled with different payment systems like SWIFT, ACH, and others. Each operates independently, creating barriers to seamless transactions.&lt;/p&gt;

&lt;p&gt;Data Isolation: Data is often siloed within specific institutions or regions, further complicating the transfer of information and funds across borders.&lt;/p&gt;

&lt;p&gt;Regulatory Frameworks: Each country or region has its own set of regulations governing financial transactions. This lack of standardization increases the complexity and cost of cross-border payments, leading to delays and inefficiencies.&lt;/p&gt;

&lt;p&gt;This shouldn’t be a problem anymore, as cryptocurrency is providing solutions. With a crypto wallet, you can easily send and receive money across the globe without the need for intermediaries. However, not everyone has a crypto wallet. As of 2024, the global cryptocurrency adoption rate is approximately 6.8%, a surprisingly small number, right? While some have eagerly jumped on the crypto train, others remain comfortable using their banks for transactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjyxp0c3oh99sfdiv4p88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjyxp0c3oh99sfdiv4p88.png" alt="stellar" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Stellar's Solution
&lt;/h2&gt;

&lt;p&gt;An exciting phase lies ahead for our journey.&lt;/p&gt;

&lt;p&gt;With Stellar, you don’t need to have a crypto wallet to make cross-border transactions, not like the general crypto solutions, Amazed? yeah.&lt;/p&gt;

&lt;p&gt;Introducing Anchors: Anchors are trusted entities that act as a bridge between the Stellar network and traditional financial systems. They facilitate the seamless movement of money between the crypto world and the real world, making the process accessible to everyone. With Stellar, users can send money effortlessly around the globe using their bank accounts, without even realizing they're interacting with a cryptocurrency system. Here's how it works:&lt;/p&gt;

&lt;p&gt;When a user sends money through their bank using Stellar, the anchor silently converts the money into a digital form on the Stellar blockchain. This digital currency is then transferred to the recipient’s region, where another anchor converts it back into the local fiat currency, depositing it directly into the receiver’s bank account. All of this happens behind the scenes, ensuring a smooth and transparent experience for the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9boqwn88iwymywutwax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9boqwn88iwymywutwax.png" alt="article " width="800" height="607"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With Stellar, sending money across the world becomes effortless, simple, cheap, fast, and secure.&lt;/p&gt;

&lt;p&gt;“The only thing that is constant is change.” This principle of continuous evolution is at the heart of Stellar's journey, as the ecosystem strives to become better and bigger. Stellar isn't just about facilitating payments and transferring value anymore. There is much more to finance than just payments.&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Next Stop: Soroban
&lt;/h2&gt;

&lt;p&gt;The future of Stellar is about expanding beyond pure payments, and that journey continues with Soroban—a groundbreaking development that brings smart contracts to the Stellar blockchain. Soroban enables developers to build endless innovations on the Stellar network, unlocking new possibilities for decentralized finance (DeFi), tokenization, and beyond.&lt;/p&gt;

&lt;p&gt;Imagine the ability to tokenize real-world assets like real estate or commodities on the Stellar blockchain. With Soroban, developers can create smart contracts that automatically handle complex transactions, manage assets, or even facilitate automated compliance. This not only broadens the scope of what Stellar can do but also opens up new avenues for financial innovation, making the ecosystem more versatile and powerful than ever before.&lt;/p&gt;
&lt;h2&gt;
  
  
  KEY FEATURES OF STELLAR
&lt;/h2&gt;

&lt;p&gt;Some key features of Stellar include:&lt;/p&gt;

&lt;p&gt;Stellar Consensus Protocol (SCP): Unlike traditional Proof of Work or Proof of Stake mechanisms, Stellar uses SCP, which is faster and more energy efficient, allowing for quick transaction confirmations.&lt;/p&gt;

&lt;p&gt;Lumens (XLM): Lumens are the native digital currency of the Stellar network. They are used to pay transaction fees and maintain account balances.&lt;/p&gt;

&lt;p&gt;Decentralized Exchange: Stellar has a built-in decentralized exchange (DEX) that allows users to trade various assets directly on the network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffg75fqb00bijudfx1otm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffg75fqb00bijudfx1otm.png" alt="Stellar features " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great job making it this far! You've built a solid understanding of the Stellar ecosystem and how its blockchain operates.&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Last Stop: Work flow of a Crowdfunding Smart Contract on soroban
&lt;/h2&gt;
&lt;h5&gt;
  
  
  Crowdfunding DApp on Soroban with Rust: Navigation for you to Build Better
&lt;/h5&gt;

&lt;p&gt;This challenge will guide you through building a crowdfunding DApp on Stellar using Soroban, whether you're a new developer, an Ethereum developer, or someone not yet familiar with Rust. Stellar, with its open financial network technology, simplifies the process. Unlike traditional crowdfunding platforms, decentralized applications (DApps) enable users to pledge funds directly to campaigns from their digital wallets, eliminating the need for intermediaries.&lt;/p&gt;

&lt;p&gt;In this final section, we’ll walk through building a crowdfunding smart contract on the Stellar blockchain.&lt;/p&gt;
&lt;h2&gt;
  
  
  Bus-stop0: 📦 Install 📚​
&lt;/h2&gt;

&lt;p&gt;Stellar smart contracts are small programs written in the Rust programming language.&lt;/p&gt;

&lt;p&gt;To build and develop contracts you need only a couple prerequisites:&lt;/p&gt;

&lt;p&gt;A Rust toolchain&lt;/p&gt;

&lt;p&gt;Node v18: &lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;Download Node&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.stellar.org/docs/build/smart-contracts/getting-started/setup#install-the-stellar-cli" rel="noopener noreferrer"&gt;Stellar CLI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Freighter Wallet:[ Freighter Wallet](&lt;a href="https://freighter.app/" rel="noopener noreferrer"&gt;https://freighter.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installing &lt;/p&gt;

&lt;p&gt;​Linux, macOS, or other Unix-like OS​&lt;/p&gt;

&lt;p&gt;If you use macOS, Linux, or another Unix-like OS, the simplest method to install a Rust toolchain is to install rustup. Install rustup with the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, install soroban-cli alias by running the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo install_soroban
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Soroban CLI is the command line interface to Soroban. It allows you to build, deploy, and interact with smart contracts, configure identities, generate key pairs, manage networks, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set Up the Soroban Contract
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo new --lib soroban_crowdfund
  cd soroban_crowdfund
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Crowd Fund workflow
&lt;/h2&gt;

&lt;p&gt;User creates a campaign.&lt;/p&gt;

&lt;p&gt;Users can pledge, transferring their token to a campaign.&lt;/p&gt;

&lt;p&gt;After the campaign ends, the campaign creator can claim the funds if the total amount pledged is more than the campaign goal.&lt;/p&gt;

&lt;p&gt;Otherwise, campaign did not reach it's goal, users can withdraw their pledge&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Campaign:
&lt;/h2&gt;

&lt;p&gt;The process begins when a user, referred to as the "campaign creator," initiates a new crowdfunding campaign.&lt;/p&gt;

&lt;p&gt;The campaign creator specifies important details such as the fundraising goal (target amount), the deadline for the campaign, and the type of token accepted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
          #[contractimpl]
          impl Crowdfund {
              pub fn initialize(
                  e: Env,
                  recipient: Address,
                  deadline: u64,
                  target_amount: i128,
                  token: Address,
              ) {
                  assert!(
                      !e.storage().instance().has(&amp;amp;DataKey::Recipient),
                      "already initialized"
                  );

                  e.storage().instance().set(&amp;amp;DataKey::Recipient, &amp;amp;recipient);
                  e.storage()
                      .instance()
                      .set(&amp;amp;DataKey::RecipientClaimed, &amp;amp;false);
                  e.storage()
                      .instance()
                      .set(&amp;amp;DataKey::Started, &amp;amp;get_ledger_timestamp(&amp;amp;e));
                  e.storage().instance().set(&amp;amp;DataKey::Deadline, &amp;amp;deadline);
                  e.storage().instance().set(&amp;amp;DataKey::Target, &amp;amp;target_amount);
                  e.storage().instance().set(&amp;amp;DataKey::Token, &amp;amp;token);
              }
          }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pledge Tokens:&lt;/p&gt;

&lt;p&gt;Users interested in supporting the campaign can pledge their tokens by transferring them to the campaign's smart contract.&lt;/p&gt;

&lt;p&gt;Each pledge is securely stored in the contract, and users can track their contributions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#[contractimpl]
  impl Crowdfund {
      pub fn deposit(e: Env, user: Address, amount: i128) {
          user.require_auth();
          assert!(amount &amp;gt; 0, "amount must be positive");
          assert!(get_state(&amp;amp;e) == State::Running, "sale is not running");
          let token_id = get_token(&amp;amp;e);
          let current_target_met = target_reached(&amp;amp;e, &amp;amp;token_id);

          let recipient = get_recipient(&amp;amp;e);
          assert!(user != recipient, "recipient may not deposit");

          let balance = get_user_deposited(&amp;amp;e, &amp;amp;user);
          set_user_deposited(&amp;amp;e, &amp;amp;user, &amp;amp;(balance + amount));

          let client = token::Client::new(&amp;amp;e, &amp;amp;token_id);
          client.transfer(&amp;amp;user, &amp;amp;e.current_contract_address(), &amp;amp;amount);

          let contract_balance = get_balance(&amp;amp;e, &amp;amp;token_id);

          // emit events
          events::pledged_amount_changed(&amp;amp;e, contract_balance);
          if !current_target_met &amp;amp;&amp;amp; target_reached(&amp;amp;e, &amp;amp;token_id) {
              // only emit the target reached event once on the pledge that triggers target to be met
              events::target_reached(&amp;amp;e, contract_balance, get_target_amount(&amp;amp;e));
          }
      }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Campaign Success:
&lt;/h4&gt;

&lt;p&gt;After the campaign ends, if the total amount pledged by all users exceeds the campaign's goal, the campaign creator can claim the funds.&lt;/p&gt;

&lt;p&gt;The funds are transferred from the smart contract to the campaign creator’s account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  #[contractimpl]
  impl Crowdfund {
      pub fn withdraw(e: Env, to: Address) {
          let state = get_state(&amp;amp;e);
          let recipient = get_recipient(&amp;amp;e);

          match state {
              State::Running =&amp;gt; {
                  panic!("sale is still running")
              }
              State::Success =&amp;gt; {
                  assert!(
                      to == recipient,
                      "sale was successful, only the recipient may withdraw"
                  );
                  assert!(
                      !get_recipient_claimed(&amp;amp;e),
                      "sale was successful, recipient has withdrawn funds already"
                  );

                  let token = get_token(&amp;amp;e);
                  transfer(&amp;amp;e, &amp;amp;recipient, &amp;amp;get_balance(&amp;amp;e, &amp;amp;token));
                  set_recipient_claimed(&amp;amp;e);
              }
              _ =&amp;gt; {}
          };
      }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Campaign Failure:
&lt;/h4&gt;

&lt;p&gt;If the campaign does not reach its goal by the deadline, the campaign is considered unsuccessful.&lt;br&gt;
In this case, users who pledged tokens can withdraw their contributions from the smart contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#[contractimpl]
impl Crowdfund {
    pub fn withdraw(e: Env, to: Address) {
        let state = get_state(&amp;amp;e);
        let recipient = get_recipient(&amp;amp;e);

        match state {
            State::Expired =&amp;gt; {
                assert!(
                    to != recipient,
                    "sale expired, the recipient may not withdraw"
                );

                // Withdraw full amount
                let balance = get_user_deposited(&amp;amp;e, &amp;amp;to);
                set_user_deposited(&amp;amp;e, &amp;amp;to, &amp;amp;0);
                transfer(&amp;amp;e, &amp;amp;to, &amp;amp;balance);

                // emit events
                let token_id = get_token(&amp;amp;e);
                let contract_balance = get_balance(&amp;amp;e, &amp;amp;token_id);
                events::pledged_amount_changed(&amp;amp;e, contract_balance);
            }
            _ =&amp;gt; {}
        };
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implementing the Crowdfunding Smart Contract&lt;/p&gt;

&lt;p&gt;Let's explain how this process can be implemented in Soroban using Rust.&lt;/p&gt;

&lt;p&gt;Data Structures&lt;/p&gt;

&lt;p&gt;We’ll define the data keys for storing campaign details like the recipient, deadline, target amount, token type, and pledges.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#[derive(Clone)]
#[contracttype]
pub enum DataKey {
    Deadline,
    Recipient,
    Started,
    Target,
    Token,
    User(Address),
    RecipientClaimed,
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initializing a Campaign&lt;/p&gt;

&lt;p&gt;The initialize the function sets up the campaign. It stores the recipient, deadline, target amount, and token type in the contract's storage.&lt;/p&gt;

&lt;p&gt;This function is called only once when the campaign is created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
        #[contractimpl]
        impl Crowdfund {
            pub fn deposit(e: Env, user: Address, amount: i128) {
                user.require_auth();
                assert!(amount &amp;gt; 0, "amount must be positive");
                assert!(get_state(&amp;amp;e) == State::Running, "sale is not running");
                let token_id = get_token(&amp;amp;e);
                let current_target_met = target_reached(&amp;amp;e, &amp;amp;token_id);

                let recipient = get_recipient(&amp;amp;e);
                assert!(user != recipient, "recipient may not deposit");

                let balance = get_user_deposited(&amp;amp;e, &amp;amp;user);
                set_user_deposited(&amp;amp;e, &amp;amp;user, &amp;amp;(balance + amount));

                let client = token::Client::new(&amp;amp;e, &amp;amp;token_id);
                client.transfer(&amp;amp;user, &amp;amp;e.current_contract_address(), &amp;amp;amount);

                let contract_balance = get_balance(&amp;amp;e, &amp;amp;token_id);

                // emit events
                events::pledged_amount_changed(&amp;amp;e, contract_balance);
                if !current_target_met &amp;amp;&amp;amp; target_reached(&amp;amp;e, &amp;amp;token_id) {
                    // only emit the target reached event once on the pledge that triggers target to be met
                    events::target_reached(&amp;amp;e, contract_balance, get_target_amount(&amp;amp;e));
                }
            }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Pledging Tokens
&lt;/h4&gt;

&lt;p&gt;The deposit function allows users to pledge tokens.&lt;/p&gt;

&lt;p&gt;Users specify the amount they want to pledge, and the smart contract securely transfers these tokens from the user to the contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; #[contractimpl]
  impl Crowdfund {
      pub fn deposit(e: Env, user: Address, amount: i128) {
          user.require_auth();
          assert!(amount &amp;gt; 0, "amount must be positive");
          assert!(get_state(&amp;amp;e) == State::Running, "sale is not running");
          let token_id = get_token(&amp;amp;e);
          let current_target_met = target_reached(&amp;amp;e, &amp;amp;token_id);

          let recipient = get_recipient(&amp;amp;e);
          assert!(user != recipient, "recipient may not deposit");

          let balance = get_user_deposited(&amp;amp;e, &amp;amp;user);
          set_user_deposited(&amp;amp;e, &amp;amp;user, &amp;amp;(balance + amount));

          let client = token::Client::new(&amp;amp;e, &amp;amp;token_id);
          client.transfer(&amp;amp;user, &amp;amp;e.current_contract_address(), &amp;amp;amount);

          let contract_balance = get_balance(&amp;amp;e, &amp;amp;token_id);

          // emit events
          events::pledged_amount_changed(&amp;amp;e, contract_balance);
          if !current_target_met &amp;amp;&amp;amp; target_reached(&amp;amp;e, &amp;amp;token_id) {
              // only emit the target reached event once on the pledge that triggers target to be met
              events::target_reached(&amp;amp;e, contract_balance, get_target_amount(&amp;amp;e));
          }
      }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checking Campaign State&lt;/p&gt;

&lt;p&gt;The contract regularly checks the state of the campaign.&lt;/p&gt;

&lt;p&gt;If the current time is before the deadline and the target amount has not been reached, the campaign continues to run.&lt;/p&gt;

&lt;p&gt;If the target is reached, the campaign is marked as successful. If the deadline passes without reaching the target, the campaign is marked as expired.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fn get_state(e: &amp;amp;Env) -&amp;gt; State {
      let deadline = get_deadline(e);
      let token_id = get_token(e);
      let current_timestamp = get_ledger_timestamp(e);

      if current_timestamp &amp;lt; deadline {
          return State::Running;
      }

      if get_recipient_claimed(e) || target_reached(e, &amp;amp;token_id) {
          return State::Success;
      }

      State::Expired
  }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we've explored how crowdfunding smart contracts work on Stellar, let's dive into this beautifully crowdfunding app built on the Stellar network . With the basics learnt, it's time to clone the code example built by stellar and fork it and build something even better on Stellar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/stellar/soroban-dapps-challenge.git 
cd soroban-dapps-challenge 
git checkout crowdfund
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conclusion&lt;br&gt;
In this tutorial, we’ve successfully guide you through building a crowdfunding DApp on Stellar using . This project demonstrates how developers can leverage what they have learnt to build better on Stellar with Soroban, using Rust for secure and efficient smart contracts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;References
Rust Programming Language&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://developers.stellar.org/docs/learn/interactive/dapps/challenges/challenge-0-crowdfund" rel="noopener noreferrer"&gt;Soroban Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://solidity-by-example.org/app/crowd-fund" rel="noopener noreferrer"&gt;Ethereum Smart Contract Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Contributors &lt;br&gt;
&lt;a class="mentioned-user" href="https://dev.to/jesdi"&gt;@jesdi&lt;/a&gt; &lt;a class="mentioned-user" href="https://dev.to/prince_eniola"&gt;@prince_eniola&lt;/a&gt; &lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>stellarchallenge</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
