<?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: achraf bradji</title>
    <description>The latest articles on DEV Community by achraf bradji (@achraf_bradji_f13374c2c17).</description>
    <link>https://dev.to/achraf_bradji_f13374c2c17</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%2F2925831%2F7e68533b-620a-470a-b9ee-af616414bca0.jpeg</url>
      <title>DEV Community: achraf bradji</title>
      <link>https://dev.to/achraf_bradji_f13374c2c17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/achraf_bradji_f13374c2c17"/>
    <language>en</language>
    <item>
      <title>Building and Updating a Decentralized Payment Streaming System (DPSS) – ERC20 Token Support and More</title>
      <dc:creator>achraf bradji</dc:creator>
      <pubDate>Tue, 29 Apr 2025 16:14:11 +0000</pubDate>
      <link>https://dev.to/achraf_bradji_f13374c2c17/building-and-updating-a-decentralized-payment-streaming-system-dpss-erc20-token-support-and-more-2i6g</link>
      <guid>https://dev.to/achraf_bradji_f13374c2c17/building-and-updating-a-decentralized-payment-streaming-system-dpss-erc20-token-support-and-more-2i6g</guid>
      <description>&lt;p&gt;In the world of &lt;strong&gt;decentralized finance&lt;/strong&gt; (DeFi), payment streams are becoming an increasingly popular way to facilitate ongoing, automatic payments. But how do we ensure that users can send and receive payments over time without losing control? That’s where the Decentralized Payment Streaming System (DPSS) comes into play.&lt;/p&gt;

&lt;p&gt;In this post, I’ll walk you through an update to my DPSS contract, transforming it from a simple ETH-only stream to a more versatile, secure, and feature-rich version that supports both ETH and ERC20 tokens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's Changed in DPSS2?&lt;/strong&gt;&lt;br&gt;
After building the initial DPSS1 contract, I realized that there were a few key features that could enhance its functionality, especially for tokenized payments in the DeFi space. Here’s what’s new in DPSS2:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ERC20 Token Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most important update is the support for ERC20 tokens. Initially, the system was limited to ETH. Now, it supports both ETH and any ERC20 token, giving users more flexibility in how they fund and receive payment streams.&lt;/p&gt;

&lt;p&gt;This update uses OpenZeppelin’s SafeERC20 library to ensure that token transfers are safe and efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pause and Resume Streams&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Users can now pause and resume payment streams. This is useful in scenarios where the payer or recipient may need to temporarily halt payments but plan to resume later.&lt;/p&gt;

&lt;p&gt;This gives more control and flexibility over payment schedules, which is vital for long-term DeFi projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Extend Stream Duration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another important update is the ability to extend the duration of an existing stream. If the payer wants to continue the stream beyond the initial duration, they can fund the stream again, which will extend its duration based on the additional funds sent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Detailed Error Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Error messages have been improved, making it easier to understand why a stream might have failed or what needs to be done to resolve the issue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Does DPSS2 Work?&lt;/strong&gt;&lt;br&gt;
The contract creates a payment stream that allows a payer to send funds to a recipient over a specified duration. Payments are released gradually based on a calculated rate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s a simplified version of the logic:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The payer sends a certain amount of tokens (ETH or ERC20) to the contract, specifying the recipient and the duration of the stream.&lt;/p&gt;

&lt;p&gt;The contract calculates the rate at which funds will be released (amount / duration).&lt;/p&gt;

&lt;p&gt;The recipient can withdraw funds periodically based on the rate, and they can even pause the stream when needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security Considerations&lt;/strong&gt;&lt;br&gt;
When working with DeFi contracts, security is a top priority. Some of the security features in DPSS2 include:&lt;/p&gt;

&lt;p&gt;Reentrancy Guard: To prevent reentrancy attacks, the contract uses OpenZeppelin’s ReentrancyGuard to ensure that functions like withdraw() can’t be exploited.&lt;/p&gt;

&lt;p&gt;SafeERC20: By using SafeERC20, token transfers are made safe by handling potential pitfalls in ERC20 implementations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why DPSS2 Matters&lt;/strong&gt;&lt;br&gt;
The new DPSS2 contract brings enhanced flexibility and security to DeFi payments, enabling projects to build more complex payment structures with ERC20 tokens, stream extensions, and pause/resume functionality.&lt;/p&gt;

&lt;p&gt;I believe this update provides the necessary tools for decentralized payment systems to handle more sophisticated use cases, especially in the world of long-term subscriptions, payments, and investments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check Out the Full Code&lt;/strong&gt;&lt;br&gt;
If you want to dive deeper into the code, I’ve uploaded the full DPSS2 contract on GitHub. You can fork, modify, and improve it for your own projects.&lt;/p&gt;

&lt;p&gt;🔗 [&lt;a href="https://github.com/Achraf012/learning-projects/blob/main/Decentralized-Payment-Streaming-System/contracts/v2.sol" rel="noopener noreferrer"&gt;https://github.com/Achraf012/learning-projects/blob/main/Decentralized-Payment-Streaming-System/contracts/v2.sol&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
I hope you found this breakdown of DPSS2 insightful. If you’re working on DeFi projects that involve periodic payments, I highly recommend looking into this contract. Feel free to reach out if you have any questions or suggestions. Always happy to collaborate!&lt;/p&gt;

&lt;h1&gt;
  
  
  Solidity #Blockchain #DeFi #SmartContracts #ERC20 #Ethereum #DeFiDevelopment #PaymentStreams #OpenZeppelin
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>🚀 Implementing Fee Logic in a Decentralized Escrow System (with Foundry Tests)</title>
      <dc:creator>achraf bradji</dc:creator>
      <pubDate>Mon, 21 Apr 2025 14:54:51 +0000</pubDate>
      <link>https://dev.to/achraf_bradji_f13374c2c17/implementing-fee-logic-in-a-decentralized-escrow-system-with-foundry-tests-f1p</link>
      <guid>https://dev.to/achraf_bradji_f13374c2c17/implementing-fee-logic-in-a-decentralized-escrow-system-with-foundry-tests-f1p</guid>
      <description>&lt;p&gt;Just wrapped up a fun yet tricky part of my escrow project: fee implementation.&lt;/p&gt;

&lt;p&gt;What I added:&lt;br&gt;
Fee payout logic &lt;/p&gt;

&lt;p&gt;Dynamic fee recipient address&lt;/p&gt;

&lt;p&gt;Full test coverage with Foundry&lt;/p&gt;

&lt;p&gt;A special Rejection contract to simulate fee transfer failures&lt;/p&gt;

&lt;p&gt;This small feature really made me appreciate how complex simple things can be in Solidity when you care about:&lt;/p&gt;

&lt;p&gt;⛽️ Gas efficiency&lt;/p&gt;

&lt;p&gt;🔒 Security&lt;/p&gt;

&lt;p&gt;✅ Test coverage&lt;/p&gt;

&lt;p&gt;One cool challenge:&lt;br&gt;
Making sure the contract reverts properly if the fee transfer fails without deleting the original amount. Sounds easy... wasn’t 😂&lt;/p&gt;

&lt;p&gt;Now that everything passes (23/23 tests 💪), I'm moving toward multisig support next.&lt;/p&gt;

&lt;p&gt;If you're also diving into Solidity, trust me — testing teaches more than coding.&lt;/p&gt;

&lt;p&gt;Let me know what you think, or if you want to walk through your own fee logic!&lt;/p&gt;

&lt;p&gt;Feel free to check out the full code and see how I implemented it on GitHub: [&lt;a href="https://github.com/Achraf012/learning-projects/tree/main/EscrowProject" rel="noopener noreferrer"&gt;https://github.com/Achraf012/learning-projects/tree/main/EscrowProject&lt;/a&gt;]&lt;/p&gt;

&lt;h1&gt;
  
  
  solidity #web3 #foundry #smartcontracts #buildinpublic #testing
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>Don’t Leave Testing for the End: A Costly Mistake I Made in My Web3 Project</title>
      <dc:creator>achraf bradji</dc:creator>
      <pubDate>Thu, 17 Apr 2025 21:32:09 +0000</pubDate>
      <link>https://dev.to/achraf_bradji_f13374c2c17/dont-leave-testing-for-the-end-a-costly-mistake-i-made-in-my-web3-project-23g7</link>
      <guid>https://dev.to/achraf_bradji_f13374c2c17/dont-leave-testing-for-the-end-a-costly-mistake-i-made-in-my-web3-project-23g7</guid>
      <description>&lt;p&gt;🧠  &lt;strong&gt;Intro&lt;/strong&gt;&lt;br&gt;
I recently built a Token Sale + Vesting system in Solidity. Like most devs on a roll, I thought:&lt;/p&gt;

&lt;p&gt;“Let me finish all the contracts first, then write the tests at the end.”&lt;/p&gt;

&lt;p&gt;Bad idea. Here's what happened — and what I learned the hard way.&lt;/p&gt;

&lt;p&gt;🔥 &lt;strong&gt;What Went Wrong&lt;/strong&gt;&lt;br&gt;
When I finally got to testing, things started breaking everywhere.&lt;/p&gt;

&lt;p&gt;Random reverts on function calls&lt;/p&gt;

&lt;p&gt;OwnableUnauthorizedAccount errors&lt;/p&gt;

&lt;p&gt;Division by zero panics&lt;/p&gt;

&lt;p&gt;Logic bugs that I didn’t notice while coding&lt;/p&gt;

&lt;p&gt;It was overwhelming. The error messages weren’t always obvious, and debugging took forever because I wasn’t sure which contract was causing the issue.&lt;/p&gt;

&lt;p&gt;🧪 &lt;strong&gt;The Turning Point&lt;/strong&gt;&lt;br&gt;
I decided to step back and test each contract in isolation, one at a time.&lt;/p&gt;

&lt;p&gt;✅ First I wrote tests just for the Vesting contract&lt;br&gt;
✅ Then I tested the TokenSale contract independently&lt;br&gt;
✅ Finally, I tested how they interacted&lt;/p&gt;

&lt;p&gt;Suddenly everything made more sense. I found the root of most bugs easily and could confidently refactor parts of the logic.&lt;/p&gt;

&lt;p&gt;🛠️ &lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;br&gt;
If you're working on a Web3/Smart Contract project, I highly recommend this approach:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test each contract right after writing it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Catch issues while they're fresh in your mind&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start with unit tests before integration tests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test the contract alone first&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simulate edge cases early&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like caps not met, wrong owner calling, or time not yet passed&lt;/p&gt;

&lt;p&gt;✍️&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
I’m still learning, but this experience was a big eye-opener. Testing smart contracts isn’t just about coverage — it’s about clarity and confidence.&lt;/p&gt;

&lt;p&gt;If you’re working on your own Solidity projects, trust me:&lt;br&gt;
Test early. It’s worth it.&lt;/p&gt;

&lt;p&gt;🏷️ Tags&lt;/p&gt;

&lt;h1&gt;
  
  
  web3 #solidity #testing #foundry #smartcontracts #blockchain #learning
&lt;/h1&gt;

</description>
    </item>
  </channel>
</rss>
