<?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: Yao Marius SODOKIN</title>
    <description>The latest articles on DEV Community by Yao Marius SODOKIN (@sodokinmarius).</description>
    <link>https://dev.to/sodokinmarius</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%2F921252%2F2c9fa1b4-1136-4e2c-9082-7cc549f66145.jpg</url>
      <title>DEV Community: Yao Marius SODOKIN</title>
      <link>https://dev.to/sodokinmarius</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sodokinmarius"/>
    <language>en</language>
    <item>
      <title>Shadowing Inherited State Variables</title>
      <dc:creator>Yao Marius SODOKIN</dc:creator>
      <pubDate>Thu, 02 Feb 2023 03:21:14 +0000</pubDate>
      <link>https://dev.to/sodokinmarius/shadowing-inherited-state-variables-4m4o</link>
      <guid>https://dev.to/sodokinmarius/shadowing-inherited-state-variables-4m4o</guid>
      <description>&lt;p&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; is a fundamental concept in object-oriented programming, allowing developers to create new classes that inherit properties and methods from existing ones. However, when it comes to state variables, there is a potential pitfall that developers should be aware of: shadowing inherited state variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shadowing&lt;/strong&gt; occurs when a subclass defines a state variable with the same name as one in its superclass, effectively hiding the inherited variable. This can lead to unexpected behavior and can make the code harder to understand and maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A practical example&lt;/strong&gt; of shadowing inherited state variables can be seen in the following Solidity code:&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.17;

contract Parent {
    uint256 public x;

    function setX(uint256 _x) public {
        x = _x;
    }
}

contract Child is Parent {
    uint256 public x;

    function setX(uint256 _x) public {
        x = _x;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, both the Parent and Child contracts have a state variable named x. The Child contract inherits from the Parent contract and has its own declaration of x, which is called "shadowing".&lt;/p&gt;

&lt;p&gt;When the Child contract's setX function is called, it updates its own x state variable and not the inherited x from the Parent contract. This is because the state variable in the Child contract shadows the inherited state variable from the Parent contract.&lt;/p&gt;

&lt;p&gt;In other words, the Child contract has a new storage location for the x state variable, separate from the one in the Parent contract. The Child contract's state variable takes precedence over the inherited state variable from the Parent contract.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In conclusion&lt;/strong&gt;, shadowing inherited state variables can lead to unexpected behavior and can make the code harder to understand and maintain. To avoid shadowing, developers should consider using a different name, using the "super" keyword, or using composition instead of inheritance. Additionally, developers should also consider the security implications of inherited state variables to ensure that sensitive information is protected.&lt;/p&gt;

</description>
      <category>cryptocurrency</category>
      <category>web3</category>
      <category>crypto</category>
    </item>
    <item>
      <title>Calling Parent Contracts</title>
      <dc:creator>Yao Marius SODOKIN</dc:creator>
      <pubDate>Thu, 02 Feb 2023 02:39:28 +0000</pubDate>
      <link>https://dev.to/sodokinmarius/calling-parent-contracts-5cl0</link>
      <guid>https://dev.to/sodokinmarius/calling-parent-contracts-5cl0</guid>
      <description>&lt;p&gt;&lt;strong&gt;Calling parent contracts in Solidity&lt;/strong&gt; can be a powerful tool for developers, allowing them to build upon existing functionality while also adding new functionality to their contracts. The most common method for calling parent contracts is through the use of the "super" keyword. &lt;br&gt;
This keyword allows a child contract to call a function from its parent contract, even if the function has been overridden in the child contract.&lt;/p&gt;

&lt;p&gt;For instance, let's consider a parent contract "Animals" that has a function "isAlive()" which returns a boolean value indicating whether the animal is alive or not. A child contract "Dogs" could inherit from the "Animals" contract and override the "isAlive()" function to include additional functionality, such as checking if the dog is trained:&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.6.0;
contract Animal {
    function isAlive() public view returns (bool) {
        return true;
    }
}

contract Dog is Animal {
    bool public isTrained;

    function isAlive() public view returns (bool) {
        if (super.isAlive() &amp;amp;&amp;amp; isTrained) {
            return true;
        }
        return false;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the "Dog" contract uses the "super" keyword to call the "isAlive()" function from its parent contract, "Animals". The child contract can then add additional functionality to the function, such as checking if the dog is trained, before returning the final value.&lt;br&gt;
However, it is important to be cautious when calling parent contracts, as this can also pose security risks. Developers must ensure that calls to parent contracts are made only by authorized parties and that sensitive information is properly protected. They should also be aware of the potential for reentrancy attacks and take appropriate measures to prevent them.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In conclusion, calling parent contracts in Solidity can provide a useful way to extend functionality while also maintaining code maintainability. By using t&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The "super" keyword, developers can easily call a parent contract's function, even if the function has been overridden in the child contract. However, it is important to consider security and take appropriate measures to protect sensitive information and prevent reentrancy attacks.&lt;/p&gt;

</description>
      <category>offers</category>
      <category>crypto</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>Implementing a Voting System in Solidity</title>
      <dc:creator>Yao Marius SODOKIN</dc:creator>
      <pubDate>Wed, 11 Jan 2023 23:17:15 +0000</pubDate>
      <link>https://dev.to/sodokinmarius/implementing-a-voting-system-in-solidity-2ekk</link>
      <guid>https://dev.to/sodokinmarius/implementing-a-voting-system-in-solidity-2ekk</guid>
      <description>&lt;p&gt;A &lt;strong&gt;voting system&lt;/strong&gt; is a crucial component of decentralized applications (dapps) that operate on the Ethereum blockchain. Solidity is the primary programming language used to write smart contracts on Ethereum, making it a natural choice for implementing a voting system.&lt;/p&gt;

&lt;p&gt;Implementing a voting system in Solidity involves several key steps:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Defining the voting structure
&lt;/h2&gt;

&lt;p&gt;This includes the &lt;strong&gt;candidates&lt;/strong&gt; or options available for voting, the number of votes each voter is entitled to, and the total number of votes cast.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Voter {
    address addr;
    bool voted;
    uint8 vote;
}

struct Candidate {
    bytes32 name;
    uint8 voteCount;
}

mapping(address =&amp;gt; Voter) public voters;
Candidate[] public candidates;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Setting up the voting mechanism:
&lt;/h2&gt;

&lt;p&gt;This includes &lt;strong&gt;functions for casting votes&lt;/strong&gt;, &lt;strong&gt;checking voter eligibility,&lt;/strong&gt; and tallying the &lt;strong&gt;results&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function vote(uint8 _candidate) public {
    require(voters[msg.sender].voted == false);
    require(_candidate &amp;lt; candidates.length);

    voters[msg.sender].vote = _candidate;
    voters[msg.sender].voted = true;
    candidates[_candidate].voteCount += 1;
}

function winningCandidate() public view returns (bytes32) {
    bytes32 winner;
    uint8 maxVotes = 0;
    for (uint8 i = 0; i &amp;lt; candidates.length; i++) {
        if (candidates[i].voteCount &amp;gt; maxVotes) {
            winner = candidates[i].name;
            maxVotes = candidates[i].voteCount;
        }
    }
    return winner;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Enforcing voter eligibility
&lt;/h2&gt;

&lt;p&gt;To ensure that only eligible voters can participate in the election, we can use the onlyOwner modifier or require statement to check that a voter's address is on a list of approved addresses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;modifier onlyOwner {
    require(msg.sender == owner);
    _;
}

function addVoter(address _voter) public onlyOwner {
    voters[_voter] = Voter(_voter, false, 0);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Ensuring security
&lt;/h2&gt;

&lt;p&gt;Several &lt;strong&gt;potential vulnerabilities&lt;/strong&gt; should be considered when implementing a voting system in Solidity. These include the potential for vote manipulation, unauthorized access to voting data, and the possibility of a malicious actor attempting to disrupt the voting process. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To mitigate these risks, it is important to employ best practices such as utilizing the require statement to validate inputs, implementing access control mechanisms, and utilizing Ethereum's built-in security features such as gas limits and time constraints.&lt;/p&gt;

&lt;p&gt;This is the basic structure and functionality of a voting system in Solidity. Of course, there are many other considerations and optimizations that can be made depending on the specific requirements of the application.&lt;br&gt;
 Additionally, it's important to thoroughly test and audit the smart contract before deploying it to the Ethereum network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Note
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;It's also important to notice that, depending on the complexity of your voting system, it may be expensive to deploy and run it on Ethereum blockchain. Keep in mind that each transaction made on the contract will require paying for Gas and the amount will depend on the complexity of the function being called, the data being stored and the current network conditions.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Debugging and Testing Solidity Smart Contracts</title>
      <dc:creator>Yao Marius SODOKIN</dc:creator>
      <pubDate>Wed, 11 Jan 2023 19:07:56 +0000</pubDate>
      <link>https://dev.to/sodokinmarius/debugging-and-testing-solidity-smart-contracts-1jjl</link>
      <guid>https://dev.to/sodokinmarius/debugging-and-testing-solidity-smart-contracts-1jjl</guid>
      <description>&lt;h2&gt;
  
  
  INTRODUCTION
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt; and &lt;strong&gt;testing&lt;/strong&gt; Solidity smart contracts are crucial steps in the development process to ensure that the contracts function as intended and do not contain any security vulnerabilities. This article will provide an overview of the tools and best practices for debugging and testing Solidity contracts.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONCEPTS COMPREHENSION
&lt;/h2&gt;

&lt;p&gt;Before diving into debugging and testing, it's important to understand the basics of the Solidity programming language. Solidity is a contract-oriented, high-level programming language for writing smart contracts. It is used for implementing smart contracts on various blockchain platforms, such as Ethereum. Smart contracts are self-executing contracts with the terms of the agreement written directly into code.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt; is the process of identifying and resolving errors or bugs in a program. There are several tools and methods available for debugging Solidity contracts.&lt;br&gt;
One of the most popular tools for debugging Solidity contracts is Truffle. Truffle is a development environment, testing framework, and asset pipeline for Ethereum. It includes a suite of tools for compiling, deploying, and testing contracts. It also provides an interactive console for debugging and interacting with contracts on the blockchain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Another useful tool for debugging Solidity contracts is &lt;strong&gt;Remix, an online solidity compiler and IDE&lt;/strong&gt;. It allows developers &lt;strong&gt;to write, test, and debug their contracts&lt;/strong&gt; in the browser. It also includes a debugger that allows developers to step through the execution of their contracts, set breakpoints, and examine the state of variables at different points in the execution.&lt;br&gt;
There are also various plugins and extensions for development environments like** Visual Studio Code** that include debugging capabilities and are useful for debugging solidity contract&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt; is the process of verifying that a program or system meets its specified requirements and behaves as expected. It is an essential step in the development process to ensure that a contract is functioning correctly and does not contain any bugs or security vulnerabilities.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The most common approach to testing Solidity contracts is to use a testing framework. &lt;strong&gt;Truffle&lt;/strong&gt;, as mentioned earlier, includes a built-in testing framework for Solidity contracts. It allows developers to write tests in JavaScript and then run them against their contracts to check that they function as expected.&lt;br&gt;
Another popular testing framework for Solidity is &lt;strong&gt;OpenZeppelin's&lt;/strong&gt; "Test Environment", which allows for the testing of smart contract in a simulated blockchain.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's important to thoroughly test a smart contract before deploying it to a production environment. This includes testing for common security vulnerabilities such as the reentrancy vulnerability and the integer overflow/underflow vulnerability.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In addition to automated testing, it's also recommended to perform manual testing, reviewing the codebase, and conducting security audit by a third-party or specialized auditor.&lt;/p&gt;
&lt;h2&gt;
  
  
  A practical example
&lt;/h2&gt;

&lt;p&gt;A practical example that demonstrates the concepts discussed in this article could be a simple smart contract for a token transfer system. Here is an example of what such a contract might look like:&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.0;

contract TokenTransfer {
    mapping (address =&amp;gt; uint) public balances;

    function transfer(address _to, uint _value) public {
        require(balances[msg.sender] &amp;gt;= _value &amp;amp;&amp;amp; _value &amp;gt; 0, "Not enough balance or invalid value");
        balances[msg.sender] -= _value;
        balances[_to] += _value;
    }
}`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;** Code comprehension**&lt;br&gt;
This contract defines a mapping called "balances" that keeps track of the number of tokens held by each address. &lt;br&gt;
It also includes a function called "transfer" that is used to transfer tokens from one address to another. &lt;br&gt;
The function takes two arguments: an address to which the tokens will be transferred, and the number of tokens to be transferred.&lt;br&gt;
The transfer function uses the Solidity require statement to check that the sender has enough tokens and the _value is more than 0 before making the transfer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt;&lt;br&gt;
To debug this contract, a developer could use Truffle or Remix to deploy the contract to a local test blockchain, and then use the interactive console or debugger to step through the execution of the transfer function, and examine the state of the contract's variables at different points in the execution. They could also set breakpoints to pause the execution and inspect variable values to detect errors or bugs in the contract's logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;br&gt;
For testing, the developer could use Truffle or OpenZeppelin's "Test Environment" to write test cases for the contract, checking that it correctly transfers tokens between addresses, that it correctly updates the balance mapping, and that it has the expected behavior when passed invalid input or called by unauthorized addresses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Exemple of testing code : 

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

&lt;/div&gt;





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

contract("TokenTransfer", (accounts) =&amp;gt; {

  let contract;
  beforeEach(async () =&amp;gt; {
    contract = await TokenTransfer.new();
  });

  it("should transfer tokens correctly", async () =&amp;gt; {
    await contract.transfer(accounts[1], 100);
    let senderBalance = await contract.balances(accounts[0]);
    let receiverBalance = await contract.balances(accounts[1]);
    assert.equal(senderBalance.toNumber(), 0, "Sender balance not updated correctly");
    assert.equal(receiverBalance.toNumber(), 100, "Receiver balance not updated correctly");
  });

  it("should fail when trying to transfer more tokens than the sender has", async () =&amp;gt; {
    try {
      await contract.transfer(accounts[1], 100, {from: accounts[0]});
      await contract.transfer(accounts[1], 100, {from: accounts[0]});
    } catch (error) {
      assert.equal(error.reason, "Not enough balance or invalid value");
    }
  });

  it("should fail when trying to transfer negative tokens", async () =&amp;gt; {
    try {
        await contract.transfer(accounts[1], -1, {from: accounts[0]});
    } catch (error) {
        assert.equal(error.reason, "Not enough balance or invalid value");
    }
  });

  it("should fail when trying to transfer 0 tokens", async () =&amp;gt; {
    try {
        await contract.transfer(accounts[1], 0, {from: accounts[0]});
    } catch (error) {
        assert.equal(error.reason, "Not enough balance or invalid value");
    }
  });
});`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Test cases comprehension&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These test cases test the following scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The correct transfer of tokens between accounts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attempts to transfer more tokens than the sender has&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Attempts to transfer negative or zero tokens&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this example : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the &lt;strong&gt;beforeEach&lt;/strong&gt; function is used to create a new instance of the contract before each test case is run. This ensures that the tests are isolated from one another and do not affect the state of the contract in unexpected ways.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The it functions&lt;/strong&gt; are used to define individual test cases. The first test case, "should transfer tokens correctly," calls the transfer function and then checks that the balance of the sender and receiver have been updated correctly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The next three test cases checks&lt;/strong&gt; for the edge cases where it should fail when the sender doesn't have enough balance or trying to transfer negative or zero tokens and they check if the reason of the failure is the expected one.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;They also test for common security vulnerabilities such as the reentrancy vulnerability and the integer overflow/underflow vulnerability by adding edge cases and malicious input to their test suite.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;p&gt;In summary, debugging and testing are crucial steps in the development of Solidity smart contracts. Using the tools and techniques described in this article can help ensure that contracts are functioning correctly and do not contain any security vulnerabilities.&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Implementing a Token Contract using Solidity</title>
      <dc:creator>Yao Marius SODOKIN</dc:creator>
      <pubDate>Wed, 11 Jan 2023 18:23:36 +0000</pubDate>
      <link>https://dev.to/sodokinmarius/implementing-a-token-contract-using-solidity-3mn6</link>
      <guid>https://dev.to/sodokinmarius/implementing-a-token-contract-using-solidity-3mn6</guid>
      <description>&lt;h2&gt;
  
  
  Intoduction
&lt;/h2&gt;

&lt;p&gt;Creating a token contract using Solidity is a common task for those working with blockchain technology. In this article, we will go through the process of implementing a basic ERC-20 compliant token contract using the Solidity programming language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keys Concepts
&lt;/h2&gt;

&lt;p&gt;Before diving into the code, it's important to understand what the ERC-20 standard is. &lt;strong&gt;ERC-20&lt;/strong&gt; is a technical standard for smart contracts on the Ethereum blockchain that defines a common set of rules for creating, managing, and transferring tokens on the Ethereum network. This standard makes it easier for developers to create and manage tokens, as well as for wallets and exchanges to interact with them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A token&lt;/strong&gt;, in the context of blockchain technology, refers to a digital asset that can be traded or transferred on a blockchain network. Tokens are typically used as a means of exchange or as a representation of ownership or access rights on a blockchain platform. Tokens can be created and managed using smart contracts, which are self-executing contracts with the terms of the agreement written directly into code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solidity&lt;/strong&gt; is a programming language specifically designed for writing &lt;strong&gt;smart contracts&lt;/strong&gt; on the Ethereum blockchain. It is similar to other programming languages such as JavaScript and C++, but it has additional features and syntax that make it well-suited for developing smart contracts on Ethereum.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Now, let's take a look at the code.&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.7.0;
`contract Token {
    // The name of the token
    string public name;

    // The symbol of the token
    string public symbol;

    // The number of decimal places for the token
    uint8 public decimals;

    // The total supply of the token
    uint256 public totalSupply;

    // Mapping from addresses to their token balance
    mapping (address =&amp;gt; uint256) public balanceOf;

    // Event for when tokens are transferred
    event Transfer(address indexed from, address indexed to, uint256 value);

    // Initialize the token with a name, symbol, and number of decimal places
    constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupply) public {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        totalSupply = _totalSupply;
        balanceOf[msg.sender] = _totalSupply;
    }

    // Transfer tokens from one address to another
    function transfer(address _to, uint256 _value) public {
        require(balanceOf[msg.sender] &amp;gt;= _value &amp;amp;&amp;amp; _value &amp;gt; 0);
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
    }
}
 `
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code defines a basic token contract with the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A name, symbol, and number of decimal places for the token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A total supply of the token&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A mapping from addresses to their token balance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A transfer function that allows for the transfer of tokens from one address to another&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The constructor function is called when the contract is first deployed to the blockchain. It takes in the token's name, symbol, number of decimal places, and total supply as parameters. It sets these values as public variables and assigns the total supply of tokens to the address that deployed the contract.&lt;/p&gt;

&lt;p&gt;The transfer function allows for the transfer of tokens from one address to another. The function takes in the address of the recipient, _to, and the number of tokens to be transferred, _value. It first checks that the sender has enough tokens and that a non-zero value is being transferred using the require statement. If the check passes, it updates the balance of the sender and recipient and emits a Transfer event, which can be used for logging or other purposes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vulnerabilities and Security measures
&lt;/h2&gt;

&lt;p&gt;This code  is a basic implementation of a token contract using Solidity, but in a real-world scenario, several security measures should be taken into account. One of the main risks is the potential for unauthorized access or theft of tokens through malicious attacks or bugs in the contract code.&lt;br&gt;
To mitigate these risks, some best practices should be applied:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use the latest version of solidity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use open-source libraries such as OpenZeppelin&lt;br&gt;
Carefully test the code and perform code review&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Keep track of vulnerabilities and upgrade the contract&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use a secure way to manage your private keys&lt;br&gt;
For instance, in the previous code, the transfer function doesn't include the check of the recipient address, if the address is invalid, the token will be locked forever. Also, the code doesn’t include any restriction to mint new tokens, a malicious attacker could create as many tokens as they want to. By using OpenZeppelin library and its SafeMath library, we can check that all the values passed to the contract and internal calculations are in the correct range and address checks, and restriction of minting new tokens.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC20/SafeERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/math/SafeMath.sol";

contract Token is SafeERC20 {
    using SafeMath for uint256;
    // The name of the token
    string public name;

    // The symbol of the token
    string public symbol;

    // The number of decimal places for the token
    uint8 public decimals;

    // The total supply of the token
    uint256 public totalSupply;

    // Mapping from addresses to their token balance
    mapping (address =&amp;gt; uint256) public balanceOf;

    // Event for when tokens are transferred
    event Transfer(address indexed from, address indexed to, uint256 value);

    // Initialize the token with a name, symbol, and number of decimal places
    constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupply) public {
        require(_totalSupply &amp;lt;= 2**256 - 1); // check totalSupply within range
        require(_decimals &amp;lt;= 18); // check decimal places within range
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        totalSupply = _totalSupply;
        balanceOf[msg.sender] = _totalSupply;
    }

    // Transfer tokens from one address to another
    function transfer(address payable _to, uint256 _value) public {
        require(_to != address(0)); // check recipient address is not the null address
        require(_value &amp;gt; 0); // check value is greater than 0
        require(balanceOf[msg.sender] &amp;gt;= _value); // check sender has sufficient balance
        balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value); // decrease sender balance
        balanceOf[_to] = balanceOf[_to].add(_value); // increase recipient balance
        emit Transfer(msg.sender, _to, _value);
    }

    function mint(address _to, uint256 _amount) public onlyOwner {
        require(_amount &amp;gt; 0);
        totalSupply = totalSupply.add(_amount);
        balanceOf[_to] = balanceOf[_to].add(_amount);
        emit Transfer(address(0), _to, _amount);
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }
    address public owner;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;p&gt;In this revised version of the code, several security improvements have been made to ensure the proper functioning of the contract and the protection of token holders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The contract inherits from the SafeERC20 contract from the OpenZeppelin library, which provides a number of security-related functions such as require that recipient address is not the null address and require that value is greater than zero.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The use of the SafeMath library for handling uint256 arithmetic operations to prevent overflow/underflow errors&lt;br&gt;
check totalSupply within range , check decimal places within range, check sender has sufficient balance&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The mint function can only be called by the contract's owner, and this is controlled by the onlyOwner modifier which checks that the msg.sender is the contract's owner before executing the function&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The owner variable is added, which stores the address of the contract's owner and can be modified by the contract's owner only.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The transfer function's parameter _to is payable, it means that ether can be sent alongside the token transfer.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These improvements add an additional layer of security to the contract, reducing the risk of unauthorized access or theft of tokens. By inheriting from the SafeERC20 contract, the contract is automatically compliant with the ERC-20 standard and can be easily integrated with other contracts and wallets that also adhere to the standard. Additionally, the use of the SafeMath library and the added checks and validation make the contract more robust against potential bugs and malicious attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, token contracts using Solidity are a common task in the blockchain development. Implementing a basic ERC-20 compliant token contract using Solidity is relatively simple. However, it is important to consider security measures to mitigate the risks of unauthorized access or theft of tokens. By using best practices and libraries such as OpenZeppelin, developers can create secure and robust smart contracts. It is crucial to thoroughly test and audit the contract code before deployment to the mainnet, to ensure that the code is as secure as possible and minimize the risk of potential vulnerabilities.&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Blockchain Transactions</title>
      <dc:creator>Yao Marius SODOKIN</dc:creator>
      <pubDate>Fri, 25 Nov 2022 16:12:40 +0000</pubDate>
      <link>https://dev.to/sodokinmarius/blockchain-transactions-41m8</link>
      <guid>https://dev.to/sodokinmarius/blockchain-transactions-41m8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Blockchain technology&lt;/strong&gt; represents a new generation of software that improves business processes. The financial industry is beginning to realize its potential after decades of investing in in-house software.&lt;br&gt;
This technology makes transactions more reliable and should therefore offer multiple applications in banking, with a very good return on investment.&lt;br&gt;
But implementing this technology is a challenge: companies cannot implement it alone. They must collaborate differently and more actively with their consumers, suppliers, and competitors.  In this article I’m going to talk about transactions flow between parties in blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Blockchain is a &lt;strong&gt;peer-to-peer&lt;/strong&gt;, distributed ledger that&lt;br&gt;
is cryptographically secure, append-only, immutable extremely hard to change), and updateable only via consensus or agreement among peers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transactions steps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 1: Operation Initiated&lt;/strong&gt;&lt;br&gt;
Let's follow the step with a basic Ether transaction. If Alicia wants to send Billy some bitcoin, she would go to a Ether wallet application either on her phone or computer where she has some Ether stored. Wallet applications are usually free downloads that create a digital wallet to purchase and/or store your cryptocurrency.&lt;/p&gt;

&lt;p&gt;It is worth mentioning here that cryptocurrencies are a function of a particular blockchain, the Etherreum blockchain only transacts bitcoin and the Ethereum blockchain can only exchange Ether. To initiate the transaction, Alicia would make a request of the system to send Ether to Billy’s wallet by specifying the amount and Billy’s Ether address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt; Step 2: Smart Contract Triggered&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
When Alicia sends her transaction to the network, it triggers a smart contract that checks with the nodes on the network to make sure Alicia has the currency to spend, and that she hasn't already spent it. Once checked, the transaction is added to a proposed block.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;step 3 :Operators Spread Transaction&lt;/u&gt; :&lt;/strong&gt;&lt;br&gt;
Proposed block is communicated to the network through the peer-to-peer protocols.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Consensus&lt;/strong&gt;&lt;br&gt;
In order for the Etherreum  network to validate a block, nodes or miners must validate the correctness of a block by completing a math problem first. The node that completes consensus algorithm equation first is rewarded with some newly minted Ether. Once a solution for the equation is reached, the other nodes can easily check its accuracy, thereby accepting the new block onto the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Spread The New Block&lt;/strong&gt;&lt;br&gt;
This block is spread throughout the network through the same peer-to-peer communications we used for the transaction. When block operators receive a copy of the new block, they add it to their copy of the distributed ledger. This guarantees that all members of the peer network agree on the current state of the blockchain’s distributed ledger.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Transaction Completed&lt;/strong&gt;&lt;br&gt;
The user’s wallet monitors for the creation of new blocks that include transactions associated with the user. When a block containing the completed code from the user’s operation is received, an event is created to notify the user that the operation is complete. When the block containing Alicia’s Ether transfer to Billy is added to the blockchain, an alert will be sent to the affected wallets that the transaction was accepted and completed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Consensus in blockchain
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Consensus is a distributed computing concept that has been used in blockchain in order to provide a means of agreeing to a single version of the truth by all peers on the blockchain&lt;br&gt;
network. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consensus Categories&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Roughly, the following describes the two main categories of consensus mechanisms:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Proof-based, leader-election lottery-based :&lt;/strong&gt; , or the Nakamoto consensus whereby a leader is elected at random (using an algorithm) and proposes a final value. This&lt;br&gt;
category is also referred to as the fully decentralized or permissionless type of consensus  mechanism. This type is well used in the Bitcoin and Ethereum blockchain in the form of  a PoW mechanism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Byzantine fault tolerance (BFT)-based&lt;/strong&gt; is a more traditional approach based on rounds of votes. This class of consensus is also known as the consortium or permissioned type of consensus mechanism. BFT-based consensus mechanisms perform well when there are a limited number of nodes, but they do not scale well. On the other hand, leader-election lottery-based (PoW) consensus  mechanisms scale very well but perform very slowly. As there is significant research being&lt;br&gt;
conducted in this area, new types of consensus mechanisms are also emerging, such as the  semi-decentralized type, which is used in the Ripple network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Consensus Algorithms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The consensus algorithms available today, or that are being researched in the context of blockchain, are presented as follows. The following is not an exhaustive list, but it includes all notable algorithms:&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Proof of Work (PoW):&lt;/strong&gt; This type of consensus mechanism relies on proof that adequate computational resources have been spent before proposing a value for acceptance by the&lt;br&gt;
network. This scheme is used in Bitcoin, Litecoin, and other cryptocurrency blockchains. Currently, it is the only algorithm that has proven to be astonishingly successful against any collusion attacks on a blockchain network, such as the Sybil attack. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;• Proof of Stake (PoS)&lt;/strong&gt;: This algorithm works on the idea that a node or user has an adequate stake in the system; that is, the user has invested enough in the system so that any malicious attempt by that user would outweigh the benefits of performing such an attack on the network. This idea was first introduced by Peercoin, and it is going to be used in the Ethereum blockchain version called Serenity. Another important concept in PoS is coin age, which is a criterion derived from the amount of time and number of coins that have not been spent. In this model, the chances of proposing and signing the &lt;br&gt;
next block increase with the coin age.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;• Delegated Proof of Stake (DPoS)&lt;/strong&gt;: This is an innovation over standard PoS, whereby&lt;br&gt;
each node that has a stake in the system can delegate the validation of a transaction to&lt;br&gt;
other nodes by voting. It is used in the BitShares blockchain.&lt;br&gt;
• &lt;strong&gt;Proof of Elapsed Time (PoET):&lt;/strong&gt; Introduced by Intel in 2016, PoET uses a Trusted Execution Environment (TEE) to provide randomness and safety in the leader- election process via a guaranteed wait time. It requires the Intel SGX (Software Guard Extensions) processor to provide the security guarantee for it to be secure. &lt;/p&gt;

&lt;p&gt;•** Proof of Deposit (PoD):** In this case, nodes that wish to participate in the network have to make a security deposit before they can mine and propose blocks. This mechanism is used in the Tendermint blockchain.&lt;/p&gt;

&lt;p&gt;•** Proof of Importance (PoI): **This idea is significant and different from PoS. PoI not only&lt;br&gt;
relies on how large a stake a user has in the system, but it also monitors the usage and movement of tokens by the user in order to establish a level of trust and importance. It is used in the NEM coin blockchain. &lt;/p&gt;

&lt;p&gt;•** Federated consensus or federated Byzantine consensus:** This mechanism is used in the stellar consensus protocol. Nodes in this protocol retain a group of publicly-trusted peers and propagate only those transactions that have been validated by the majority of trusted nodes.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Reputation-based mechanisms:&lt;/strong&gt; As the name suggests, a leader is elected by the reputation it has built over time on the network. It is based on the votes of other members.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Practical Byzantine Fault Tolerance (PBFT):&lt;/strong&gt; This mechanism achieves SMR, which  provides tolerance against Byzantine nodes. Various other protocols, including PBFT,&lt;br&gt;
PAXOS, RAFT, and Federated Byzantine Agreement (FBA), are also being used or have  been proposed for use in many different implementations of distributed systems and&lt;br&gt;
blockchains.&lt;br&gt;
• &lt;strong&gt;Proof of Activity (PoA):&lt;/strong&gt; This scheme is a combination of PoS and PoW, which ensures&lt;br&gt;
that a stakeholder is selected in a pseudorandom but uniform fashion. This is a comparatively more energy-efficient mechanism as compared to PoW. It utilizes a new concept called "Follow the Satoshi." In this scheme, PoW and PoS are combined together  to achieve consensus and a good level of security. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;• Proof of Capacity (PoC):&lt;/strong&gt; This scheme uses hard disk space as a resource to mine the blocks. This is different from PoW, where CPU resources are used. In PoC, hard disk&lt;br&gt;
space is utilized for mining and, as such, is also known as hard drive mining. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;• Proof of Storage:&lt;/strong&gt; This scheme allows for the outsourcing of storage capacity. This scheme is based on the concept that a particular piece of data is probably stored by&lt;br&gt;
a node, which serves as a means to participate in the consensus mechanism. Several variations of this scheme have been proposed, such as Proof of Replication, Proof of Data Possession, Proof of Space, and Proof of Space-time.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Proof of Authority (PoA):&lt;/strong&gt; This scheme utilizes the identity of the participants called validators as a stake on the network. Validators are known and have the authority&lt;br&gt;
to propose new blocks.  Validators propose the new blocks and validate them as per blockchain rules. Commonly used PoA algorithms are Clique and Aura.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Smart Contracts

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;u&gt; Definition &lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
A smart contract is a secure and unstoppable computer program representing an agreement that is&lt;br&gt;
automatically executable and enforceable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Smart Contract  explained in details &lt;/u&gt; :&lt;/strong&gt; They are computer programs that execute an action based on terms and conditions.&lt;br&gt;
Can also be known as chain code.&lt;br&gt;
&lt;strong&gt;Smart contracts&lt;/strong&gt; have terms recorded in a computer language instead of legal language. Smart contracts are not necessarily legally binding and do not need multiple participants.&lt;br&gt;
Each step of a smart contract can only be implemented after the execution of the immediate former step.&lt;br&gt;
Smart contracts are written in Solidity, a programming language designed for developing smart contracts that run on the Ethereum Virtual Machine.&lt;br&gt;
The smart contracts act as a foundation to build decentralized applications (DApps).&lt;br&gt;
Once executed, the information in the smart contract is stored on a blockchain which cannot be altered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Smart contracts  features 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Accuracy&lt;/strong&gt;&lt;br&gt;
Replacing human intermediaries with executable code ensures the process will always be performed the same. &lt;br&gt;
&lt;strong&gt;Cost savings&lt;/strong&gt;&lt;br&gt;
Replacing intermediaries often provides significant cost reduction.&lt;br&gt;
&lt;strong&gt;Efficiency&lt;/strong&gt;&lt;br&gt;
Removing process intermediaries often results in significant process efficiency gains.&lt;br&gt;
&lt;strong&gt;Backup&lt;/strong&gt;&lt;br&gt;
A blockchain and smart contract deployed to it can provide a permanent record, allowing for auditing, insight, and traceability, even if the creator is no longer in business.&lt;br&gt;
&lt;strong&gt;Autonomy&lt;/strong&gt;&lt;br&gt;
Smart contracts can be developed by anyone, no need for intermediaries such as lawyers, brokers, or auditors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Smart Contracts properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In summary, a smart contract has the following properties:&lt;br&gt;
Automatically executable: It is self-executable on a blockchain without requiring any intervention.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enforceable: **This means that all contract conditions are enforced automatically.&lt;br&gt;
**Secure:&lt;/strong&gt; This means that smart contracts are tamper-proof (or tamper-resistant) and run  with security guarantees. The underlying blockchain usually provides these security  guarantees; however, the smart contract programing language and the smart contract code themselves must be correct, valid, and verified.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deterministic:&lt;/strong&gt; The deterministic feature ensures that smart contracts always produce the same output for a specific input. Even though it can be considered to be part of the&lt;br&gt;
secure property, defining it here separately ensures that the deterministic property is considered one of the important properties. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Semantically sound:&lt;/strong&gt; This means that they are complete and meaningful to both people and computers.&lt;br&gt;
** Unstoppable:** This means that adversaries or unfavorable conditions cannot negatively affect the execution of a smart contract. When the smart contracts execute, they complete&lt;br&gt;
their performance deterministically in a finite amount of time.&lt;/p&gt;

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

</description>
      <category>gratitude</category>
    </item>
  </channel>
</rss>
