<?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: Yassine Kosrani</title>
    <description>The latest articles on DEV Community by Yassine Kosrani (@yessin_at_dev).</description>
    <link>https://dev.to/yessin_at_dev</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%2F2054970%2F3a8dea3a-e664-4058-b93d-7d698fa0b16b.jpeg</url>
      <title>DEV Community: Yassine Kosrani</title>
      <link>https://dev.to/yessin_at_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yessin_at_dev"/>
    <language>en</language>
    <item>
      <title>Microservices vs. Monolithic Architecture in .NET Applications</title>
      <dc:creator>Yassine Kosrani</dc:creator>
      <pubDate>Wed, 11 Sep 2024 19:20:10 +0000</pubDate>
      <link>https://dev.to/yessin_at_dev/microservices-vs-monolithic-architecture-in-net-applications-4lhb</link>
      <guid>https://dev.to/yessin_at_dev/microservices-vs-monolithic-architecture-in-net-applications-4lhb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prelude&lt;/strong&gt;&lt;br&gt;
First of all, let’s break down what monolithic and microservices are: a monolithic application is built as a single unit, while microservices architecture is a collection of smaller, independently deployable services.&lt;br&gt;
We could simply consider them as simple as that, but we’ll dive deeper to discover the origins of these types of architecture so we’ll be able to define which one suits us the most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monolithic architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This architecture is a traditional way of modeling a software, where all components of the application are interConnected and interdependent, in this architecture, the application is built as a single unit where all its functionalities are in one code base, we conclude that the large and complex the application becomes the harder it is to control and in terms of scalability this gets harder also because simply we are replicating the entire application .&lt;/p&gt;

&lt;p&gt;A typical Monolithic .Net app might be a single ASP.NET core web app that include the basic layers as data access , business logic in one project. For example lets take a Movies recommendation app structure :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MoviesRecommendationApp/
Controllers/
Models/
Services/
View/
Data/
Program.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As mentioned earlier monolithic app gets hard to control when the project gets larger and complex ,in this context Microservices where introduced. In 2005 during a Web Services Edge conference Peter Rodgers introduced in his presentation the term “Micro Web services” against conventional thinking.&lt;/p&gt;

&lt;p&gt;Among the biggest transitions we can site NETFLIX‘s journey from a monolithic DVD rental service to a microservices based streaming giant , on 2009 Netflix started their monolithic and they completed their transition around 2016.This allowed them to scale rapidly and they became a huge platform handling millions of streams.&lt;/p&gt;

&lt;h2&gt;
  
  
  Microservices
&lt;/h2&gt;

&lt;p&gt;In .Net applications microservices can be a good choice in terms of flexibility , you get to choose the most suitable .Net frame work for each microservices ( .Net core , .Net5) and focused services are easier to understand, debug, and maintain compared to monolithic .&lt;/p&gt;

&lt;p&gt;To prevent cascading problems you might want to use libraries like ‘Polly’ in which circuit breaker patterns are implemented, to provide tracing and logging applications insights are a must .As microservices grow in complexity ,Domain-driven-design principles are also applied to maintain clear boundaries and make sure each service aligns with specific business logic, in other words , this means that each microservice has its own domain model to ensure its maintainability and scalability .&lt;/p&gt;

&lt;h2&gt;
  
  
  Meme season
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshnobij4mecx70is4353.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fshnobij4mecx70is4353.jpeg" alt="meme" width="283" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After microservices became a decent technique, some developers don’t use it wisely, they implement microservices arcs in projects that are clearly monolithic in type and by doing so, they start promoting their projects as a well-structured, advanced application just to increase the cost for their customers, it’s like killing a bug with a bazooka.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making the decision
&lt;/h2&gt;

&lt;p&gt;Making the right decision can be crucial sometimes ,It would help you gain time and lower your costs ,So if you’ve got a small team working on a straightforward app that’s not likely to blow up in complexity, sticking with a monolith might be your best choice . It’s simpler to develop, deploy, and manage when you’ve just started. Overall ,if you’re looking at a complex system that’s gonna grow like crazy, or you need different parts of your app to scale independently, that’s where microservices start to glow .Anything else monolithic structure is your best choice .&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>microservices</category>
      <category>systemdesign</category>
      <category>programming</category>
    </item>
    <item>
      <title>Smart Contract Dev : Hands-On with Truffle, Ganache and Solidity</title>
      <dc:creator>Yassine Kosrani</dc:creator>
      <pubDate>Wed, 11 Sep 2024 12:39:33 +0000</pubDate>
      <link>https://dev.to/yessin_at_dev/smart-contract-dev-hands-on-with-truffle-ganache-and-solidity-27jm</link>
      <guid>https://dev.to/yessin_at_dev/smart-contract-dev-hands-on-with-truffle-ganache-and-solidity-27jm</guid>
      <description>&lt;p&gt;Best guide for Developing, Deploying and Testing Smart Contracts using truffle and ganache .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Overview:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
In this guide, we’ll set up an environment that simulates the real Ethereum network without using the usual testnets provided by Ethereum, such as Sepolia or Goerli. Instead, our testnet will be local, using the Ganache client, which automatically mines blocks instantly. This simulates a real blockchain environment without waiting for actual block times, allowing for rapid testing and development. I prefer this method over traditional testnets because it eliminates the need to collect test Ether from faucets, saving time. However, this method has some drawbacks, which we’ll discuss later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Truffle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Truffle is a comprehensive development framework for building, testing, and deploying smart contracts on Ethereum, streamlining the entire blockchain development process, we’ll link it to the ganache client for our tests rather than the actual Ethereum network ‘mainnet’.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;:&lt;br&gt;
In this guide, we’re not using any IDE. The primary tools are Windows PowerShell and Node Package Manager (npm)."&lt;/p&gt;

&lt;p&gt;It might be unusual for beginners to work without any GUI but this method really helped me getting hand on hand with smart contract development using only CLI , so first of all you should install Node.js on your system here’s a link for downloading it :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en/download/prebuilt-installer?source=post_page-----b3850b478ea8--------------------------------" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Preparing Your Development Environment:**
&lt;/h2&gt;

&lt;p&gt;After installing Node.js on your system, we proceed to install the required libraries and frameworks. We will install the Ganache client, the Truffle framework, the Solidity compiler, and the Web3 library. Open the command prompt and type:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g solc web3 truffle ganache&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Make sure, after executing that command, to check if they are installed. For example, try checking the Truffle version as shown in the following screenshot:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm truffle --version&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjmib8o8gy1bk0ydxarf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcjmib8o8gy1bk0ydxarf.png" alt="Truffle version" width="750" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;you could see all versions with this command :&lt;br&gt;
&lt;code&gt;npm list&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Following step
&lt;/h2&gt;

&lt;p&gt;Now after setting all requirements lets start developing , Create your project folder and navigate to it as cited in the following screenshot&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcu287hm9j6tfvl4sy3ru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcu287hm9j6tfvl4sy3ru.png" alt="create project" width="741" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;commands :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir ProjectName

cd ProjectName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now lets initialize a truffle project :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;truffle init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9pd7zlikubhct7c5ujx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9pd7zlikubhct7c5ujx.png" alt="Initialize Truffle project" width="716" height="325"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Truffle will create a new project folder in the specified folder with standard project folders :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ej56dzk8wkggmhsiyr1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5ej56dzk8wkggmhsiyr1.png" alt="New project folder" width="728" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets start configuring our truffle project , Open the truffle-config.js file using Notepad to coordinate it with the Ganache client later when we start the service .&lt;/p&gt;

&lt;p&gt;uncomment the network section and set it as this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;networks: {

    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 8545,            // Standard CLI Ethereum port
     network_id: "*"     
     }
},
compilers: {
    solc: {
      version: "0.8.26" ,   // Fetch exact version from solc-bin (default: truffle's version)
      settings: {          
       optimizer: {
         enabled: true,
          runs: 200
       }

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Do not forget to fetch the exact version of the solidity compiler try: npm solc — version&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Solidity
&lt;/h2&gt;

&lt;p&gt;Now, let’s create our smart contract, which we’ll deploy later. I prefer writing my contracts from scratch in Notepad and then compiling them using Truffle directly. This method has helped me get comfortable with the Solidity programming language. However, if you’re familiar with using an IDE like Remix, that would work well too. The following code is a sample of the contract I created: it’s an ERC20 token named Skaltuchet, using the OpenZeppelin library&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Do not forget to install Openzepplin’s library , try :&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;npm install openzeppelin/contracts@5.0.2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add this code to the contracts folder as solidity code (.sol)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pragma solidity ^0.8.26;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract Skaltuchet is ERC20, Ownable {
    uint256 public constant TOKENS_PER_ETH = 1000;
    uint256 public constant INITIAL_SUPPLY = 1000000 * 10**18; // 1 million tokens, considering 18 decimals

    // Event to track token purchases
    event TokensPurchased(address indexed buyer, uint256 amountOfETH, uint256 amountOfTokens);

    constructor(address initialOwner) ERC20("Skaltuchet", "SKT") Ownable(initialOwner) {
        _mint(initialOwner, INITIAL_SUPPLY / 2);       // Mint 500,000 tokens to the deployer
        _mint(address(this), INITIAL_SUPPLY / 2);    // Mint 500,000 tokens to the contract itself
    }

    function buyTokens() public payable {
        require(msg.value &amp;gt; 0, "Send ETH to buy tokens");

        uint256 tokensToBuy = (msg.value * TOKENS_PER_ETH * 10**decimals()) / 1 ether;
        require(balanceOf(address(this)) &amp;gt;= tokensToBuy, "Not enough tokens in the reserve");

        _transfer(address(this), msg.sender, tokensToBuy);

        // Emit the TokensPurchased event
        emit TokensPurchased(msg.sender, msg.value, tokensToBuy);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After saving the contract’s code in the contracts folder, let’s proceed to the migration.js file to ensure a successful deployment. In the migrations folder, add a new file (2_Deploy.js) that provides a script to deploy smart contracts to Ethereum networks (such as development, testnets, or mainnet). In our case, it’s the Ganache client. The deployment is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Skaltuchet = artifacts.require("Skaltuchet");

module.exports = function (deployer, network, accounts) {
    // Use the first account from the ganache client accounts as the owner 
    const initialOwner = accounts[0];

    deployer.deploy(Skaltuchet, initialOwner)
        .then(() =&amp;gt; {
            console.log("Skaltuchet contract deployed successfully!");
        })
        .catch(error =&amp;gt; {
            console.error("Deployment failed:", error);
        });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our case probably all things are good we settled truffle-configuration, smart contract, and the deployment file as well, Now let’s start the ganache client, and run this command in the command prompt.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ganache&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2wvtgk76epj8okic71x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2wvtgk76epj8okic71x.png" alt="Starting the ganache client" width="743" height="107"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Normally the ganache client should start RPC Listening on 127.0.0.1:8545(local host as defined in the truffle config)and you’ll have 10 accounts with 1000 ETH in each one of them as in the following screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdovkjjnsly01251g6x89.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdovkjjnsly01251g6x89.png" alt="Ganache starts mining" width="738" height="593"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the following steps, we’ll compile our contract, deploy it to the test network, interact with it, and test its features.&lt;/p&gt;

&lt;p&gt;keep the ganache running and open another command prompt window ,Run these command :&lt;br&gt;
&lt;code&gt;truffle compile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wy5805tji8uli67brf7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1wy5805tji8uli67brf7.png" alt="Contract compiled successfully" width="734" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;when compiled successfully lets deploy it by running :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;truffle migrate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F569t6p81dh8jticdsfwm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F569t6p81dh8jticdsfwm.png" alt="Contract deployed successfully" width="738" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we could clearly see in the window where ganache is running the details of deployment as the transaction hash and and block number as shown in the following screenshot .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiah4k3ecqn60p8wm147n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiah4k3ecqn60p8wm147n.png" alt="Contract Deployment Tracking" width="733" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we managed successfully to deploy the contract, Lets try now interacting with it to see if its working as intended or not ,In this concept truffle offer us a tool for interacting with the deployed contract , Its the truffle console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interacting with the deployed contract&lt;/strong&gt;&lt;br&gt;
To summarize, we deployed our contract successfully lets now interact with it , by running this command:&lt;br&gt;
&lt;code&gt;truffle console&lt;/code&gt;&lt;br&gt;
you will enter in a JavaScript environment to interact with the deployed contract .here’s a code example to interact with the contract.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const Skaltuchet = await artifacts.require("Skaltuchet").deployed()&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const contractAddress = await Skaltuchet.address
const contractBalance = await Skaltuchet.balanceOf(contractAddress)
console.log("Contract SKT balance:", web3.utils.fromWei(contractBalance.toString(), 'ether'), "SKT")

const accounts = await web3.eth.getAccounts()
const ownerAddress = accounts[0]
const ownerBalance = await Skaltuchet.balanceOf(ownerAddress)
console.log("Owner SKT balance:", web3.utils.fromWei(ownerBalance.toString(), 'ether'), "SKT")

const ownerEthBalance = await web3.eth.getBalance(ownerAddress)
console.log("Owner ETH balance:", web3.utils.fromWei(ownerEthBalance.toString(), 'ether'), "ETH")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can save this code to file.js, then navigate to its directory and run: node file.js. Alternatively, you can execute it command by command in the Truffle console, as shown in the following screenshot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdhp1ebtnnpgdlrgrook.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmdhp1ebtnnpgdlrgrook.png" alt="Interacting with the deployed Contract" width="746" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;lets try performing a buy transaction now from another account from accounts&lt;/p&gt;

&lt;p&gt;and then check its balance, Here’s a js code example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const buyer = accounts[1]// choose acount one as the buyer 
let buyerBalance = await Skaltuchet.balanceOf(buyer)
console.log("Buyer's initial SKT balance:", web3.utils.fromWei(buyerBalance.toString(), 'ether'), "SKT")

//Check the contract's initial SKT balance:
const ethAmount = web3.utils.toWei('1', 'ether')
const result = await Skaltuchet.buyTokens({ from: buyer, value: ethAmount })
console.log("Buy transaction hash:", result.tx)

//perform a buy transaction
const ethAmount = web3.utils.toWei('1', 'ether')
const result = await Skaltuchet.buyTokens({ from: buyer, value: ethAmount })
console.log("Buy transaction hash:", result.tx)

//check buyer's new balance 
buyerBalance = await Skaltuchet.balanceOf(buyer)
console.log("Buyer's new SKT balance:", web3.utils.fromWei(buyerBalance.toString(), 'ether'), "SKT")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As shown in the screenshot the buy transaction was succesfull and account1 got his ‘SKT’ tokens.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F139ejvvoovs4im6im8qi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F139ejvvoovs4im6im8qi.png" alt="Successful Buy transaction" width="745" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SUMMARY:
&lt;/h2&gt;

&lt;p&gt;In the previous part we handled interacting with the deployed smart contract and testing it via Truffle console, You can see Truffle with Ganache is quite a good tool for creating deploying, and testing smart contracts, But it has some challenging steps when you want to use deployed contracts on the real Ethereum network (mainnet 1) like using Uniswap router, for example, you would probably need to fork the deployed contract on the ganache client and use an infura provider.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
