<?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: Ali Nasirlou</title>
    <description>The latest articles on DEV Community by Ali Nasirlou (@alinasirlou).</description>
    <link>https://dev.to/alinasirlou</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4093883%2Fd9055755-e0ad-42f9-8daa-95abacab9a87.png</url>
      <title>DEV Community: Ali Nasirlou</title>
      <link>https://dev.to/alinasirlou</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alinasirlou"/>
    <language>en</language>
    <item>
      <title>3 Things I Learned Building a Smart Contract Project with Foundry</title>
      <dc:creator>Ali Nasirlou</dc:creator>
      <pubDate>Wed, 26 Aug 2026 11:19:35 +0000</pubDate>
      <link>https://dev.to/alinasirlou/3-things-i-learned-building-a-smart-contract-project-with-foundry-21he</link>
      <guid>https://dev.to/alinasirlou/3-things-i-learned-building-a-smart-contract-project-with-foundry-21he</guid>
      <description>&lt;p&gt;When I started building my NFT marketplace in Solidity, my main goal was simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make it work.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But as the project grew, I realized that writing Solidity code that works is only part of the job.&lt;/p&gt;

&lt;p&gt;Here are three things I learned while building the project with &lt;strong&gt;Solidity, Foundry, and OpenZeppelin&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Working code doesn't mean secure code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A function can work perfectly and still be vulnerable.&lt;/p&gt;

&lt;p&gt;For example, a marketplace purchase function may look simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function buy(uint256 listingId) external payable {
    Listing storage listing = listings[listingId];

    require(msg.value == listing.price);

    // Transfer NFT
    // Transfer payment
    // Update listing
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But then you have to ask:&lt;/p&gt;

&lt;p&gt;What if the listing was already purchased?&lt;br&gt;
What if the seller no longer owns the NFT?&lt;br&gt;
What if approval was revoked?&lt;br&gt;
What happens during an external call?&lt;br&gt;
Can the function be reentered?&lt;/p&gt;

&lt;p&gt;This changed the way I approach smart contracts.&lt;/p&gt;

&lt;p&gt;I don't just ask:&lt;/p&gt;

&lt;p&gt;"Does this function work?"&lt;/p&gt;

&lt;p&gt;I also ask:&lt;/p&gt;

&lt;p&gt;"How could someone break it?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Architecture becomes important very quickly&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the beginning, putting everything into one contract seems fine.&lt;/p&gt;

&lt;p&gt;But an NFT marketplace can eventually include:&lt;/p&gt;

&lt;p&gt;Listings&lt;br&gt;
Purchases&lt;br&gt;
Offers&lt;br&gt;
Auctions&lt;br&gt;
Rentals&lt;br&gt;
Fees&lt;br&gt;
Administration&lt;br&gt;
Queries&lt;/p&gt;

&lt;p&gt;Putting all of this into one huge contract quickly becomes difficult to maintain.&lt;/p&gt;

&lt;p&gt;For my project, I started separating responsibilities into different components:&lt;/p&gt;

&lt;p&gt;MarketCore.sol&lt;br&gt;
MarketAdmin.sol&lt;br&gt;
MarketValidation.sol&lt;br&gt;
MarketEvents.sol&lt;br&gt;
MarketErrors.sol&lt;br&gt;
MarketQuery.sol&lt;br&gt;
MarketplaceStorage.sol&lt;/p&gt;

&lt;p&gt;The important lesson wasn't simply "use more contracts."&lt;/p&gt;

&lt;p&gt;It was:&lt;/p&gt;

&lt;p&gt;Give each part of the system a clear responsibility.&lt;/p&gt;

&lt;p&gt;This makes the code easier to understand, test, and audit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Testing shouldn't only prove that things work&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With Foundry, it's easy to write tests for the happy path:&lt;/p&gt;

&lt;p&gt;Create listing&lt;br&gt;
      ↓&lt;br&gt;
Buy NFT&lt;br&gt;
      ↓&lt;br&gt;
NFT transferred&lt;/p&gt;

&lt;p&gt;But smart contract testing should go further.&lt;/p&gt;

&lt;p&gt;I also want to know what happens when:&lt;/p&gt;

&lt;p&gt;Wrong payment&lt;br&gt;
Unauthorized caller&lt;br&gt;
Invalid listing&lt;br&gt;
Revoked approval&lt;br&gt;
Already purchased NFT&lt;br&gt;
Repeated calls&lt;br&gt;
Failed external call&lt;/p&gt;

&lt;p&gt;This is where testing starts becoming security research.&lt;/p&gt;

&lt;p&gt;Instead of only testing:&lt;/p&gt;

&lt;p&gt;"Can a user do this?"&lt;/p&gt;

&lt;p&gt;I try to test:&lt;/p&gt;

&lt;p&gt;"Can a malicious user make this behave differently than intended?"&lt;/p&gt;

&lt;p&gt;Final Thoughts&lt;/p&gt;

&lt;p&gt;Building this project taught me that smart contract development isn't just about writing Solidity.&lt;/p&gt;

&lt;p&gt;It's about thinking about:&lt;/p&gt;

&lt;p&gt;Architecture → State → Edge cases → Testing → Security&lt;/p&gt;

&lt;p&gt;And the biggest lesson I've learned so far is:&lt;/p&gt;

&lt;p&gt;A smart contract isn't good just because it works. You need to understand how it behaves when someone tries to break it.&lt;/p&gt;

&lt;p&gt;I'm continuing to improve the project and dive deeper into smart contract security and auditing.&lt;/p&gt;

&lt;p&gt;More experiments and lessons coming soon.&lt;/p&gt;

</description>
      <category>security</category>
      <category>solidity</category>
      <category>web3</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
