|
Sarthak Saxena Oodles

Sarthak Saxena (Backend-Associate Consultant L2- Development)

Experience:2+ yrs

Sarthak, an experienced back-end developer, specializes in Node.js and possesses a profound understanding of web3 technology. He has hands-on experience with a plethora of tools and frameworks, including Solidity, Express.js, Remix, Twilio, and databases such as MongoDB and Postgres. Leveraging his extensive expertise in Solidity and back-end development, Sarthak consistently delivers exceptional results in any project related to his field.

Sarthak Saxena Oodles
Sarthak Saxena
(Associate Consultant L2- Development)

Sarthak, an experienced back-end developer, specializes in Node.js and possesses a profound understanding of web3 technology. He has hands-on experience with a plethora of tools and frameworks, including Solidity, Express.js, Remix, Twilio, and databases such as MongoDB and Postgres. Leveraging his extensive expertise in Solidity and back-end development, Sarthak consistently delivers exceptional results in any project related to his field.

LanguageLanguages

DotENGLISH

Conversational

DotHINDI

Conversational

Skills
Skills

DotAPI Documentation

80%

DotMySQL

40%

DotNode Js

80%

DotMetaMask

80%

DotEtherscan

80%

DotJavascript

80%

DotGithub/Gitlab

60%

DotCoinbase API

80%

DotBlockchain

80%

DotNestJS

80%

DotNo SQL/Mongo DB

80%
ExpWork Experience / Trainings / Internship

Apr 2022-May 2024

SDE1- BACKEND

plot 94, sector 44, Gurgaon, Haryana


Dhwani Rual Information Systems

plot 94, sector 44, Gurgaon, Haryana

Apr 2022-May 2024

EducationEducation

2017-2021

Dot

future institute of engineering and technology

B.Tech-Computer science and Engineering

Top Blog Posts
Smart Contract Upgradability | Proxy Patterns in Solidity

Once deployed, smart contracts cannot be changed or tampered with since they are immutable. However, a contemporary method of smart contract development that can be upgraded is the Ethereum blockchain's Universal Upgradeable Proxy Standard (UUPS). By making the upgrading process easier and improving gas efficiency, it overcomes some drawbacks of earlier proxy patterns, most notably the Transparent Proxy Pattern.

 

UUPS consists of two main components: the proxy and implementation contracts.

 

Smart Contract Upgradability | Proxy Patterns in Solidity

 

a)Proxy Contract

 

  • Maintains a specific storage slot for the address of the implementation contract.
  • Users interact with the proxy rather than the implementation directly. This ensures that state and logic remain consistent across upgrades

 

b) Implementation Contract

 

`When deploying a UUPS setup, it's essential to initialize the implementation through the proxy to ensure that state variables are stored correctly in the proxy's storage rather than in the implementation's storage, which is essential for maintaining the integrity and upgradeability of the contract.

All the versions of the implementation contract share the same storage space so that`s why sequencing matters while initializing variables.

 

In the UUPS pattern, constructors are generally not used due to the proxy design.

 

  • Reasons for Not Using Constructors

     

Storage Separation

 

The implementation contract does not directly manage state variables; instead, these variables are stored in the proxy's storage. Since constructors are executed during contract deployment and would initialize state variables in the implementation contract, using them would lead to incorrect storage allocation and could result in state variables being stored in the implementation rather than the proxy.

 

Also, Check | How to Create a Simple Supply Chain Smart Contract

 

Initialization Function 

 

These contracts utilize an initializer function that is called after deployment. This function is designed to set up state variables and can include security mechanisms to ensure it is only called once, preventing re-initialization attacks.

 

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract Version1 is
    Initializable,
    ERC20Upgradeable,
    UUPSUpgradeable,
    OwnableUpgradeable
{
    uint256 public value;

    // Initializer function to replace constructor
    function initialize() public initializer {
        __ERC20_init("Mars", "MARS");
        __Ownable_init(_msgSender()); // Pass the owner address here
        value = 5;
        __UUPSUpgradeable_init();
        _mint(msg.sender, 10000000 * 10 ** decimals());
    }

    // Upgradeable authorization for upgrades (only owner can upgrade)
    function _authorizeUpgrade(
        address newImplementation
    ) internal override onlyOwner {}

    function getValue() public view returns (uint256) {
        return value;
    }
}

contract Version2 is Version1 {
    function version() public pure returns (string memory) {
        return "V2";
    }
}

contract Version3 is Version1 {
    function version() public pure returns (string memory) {
        return "V3";
    }
}

 

For the above contract we are upgrading the contract versions from "V`1" to "V3", below are the test cases for the proxy contract.

 

Also, Explore | How to Write and Deploy Modular Smart Contracts

 

const {
  loadFixture,
} = require("@nomicfoundation/hardhat-toolbox/network-helpers");
const hardhat = require("hardhat");
const assert = require("assert");

describe("Proxy", function () {

  describe("Deployment", async function () {
    async function deployOneYearLockFixture() {
      const contract = await hardhat.ethers.getContractFactory("Version1");
      const contractVersion2 = await hardhat.ethers.getContractFactory("Version2");
      const contractVersion3 = await hardhat.ethers.getContractFactory("Version3");
      const proxyContract = await hardhat.upgrades.deployProxy(contract, { kind: "uups" })
      return {  proxyContract, contractVersion3, contractVersion2 }
    }

    describe("Versions", function () {
      it("Should set the right output", async function () {
        const { contractVersion3, proxyContract, contractVersion2 } = await loadFixture(deployOneYearLockFixture);
        assert(await proxyContract.name() == 'Mars')
        assert(await proxyContract.getValue() == 5n)
        const contractV2 = await hardhat.upgrades.upgradeProxy(proxyContract, contractVersion2)

        assert(await contractV2.getValue() == 5n)
        assert(await contractV2.version() == 'V2')


        const contractV3 = await hardhat.upgrades.upgradeProxy(proxyContract, contractVersion3)

        assert(await contractV3.getValue() == 5n)
        assert(await contractV3.version() == 'V3')
      });
    });
  })
})

 

Use the following command to run and verify the test cases for the proxy contract

 


- npx hardhat test

 

Also, Read | How to Create Play-to-Earn Gaming Smart Contracts


Conclusion


In conclusion, the Universal Upgradeable Proxy Standard (UUPS) provides a robust framework for developing upgradeable smart contracts on Ethereum. By leveraging a proxy architecture that separates logic from state, it allows for efficient upgrades while maintaining critical aspects of security and decentralization inherent to blockchain technology. As smart contract developers continue to navigate the complexities of smart contract deployment and management, UUPS stands out as a preferred method for ensuring that decentralized applications can evolve over time without compromising their foundational integrity.

Category: Blockchain
How to Create a Smart Contract for Lottery System

Implementing a lottery smart contract using Solidity is an exciting venture into the world of blockchain technology. This guide will walk you through all the essential components of a lottery contract, using the provided functions as a foundation. For more information about smart contracts, visit our smart contract development services
 

An Overview of the Lottery Contract

 

The lottery contract enables players to enter by sending a small amount of Ether, and a winner is selected randomly. The contract is designed to be simple yet effective, ensuring transparency and fairness in the lottery program.

 

Also, Explore | A Quick Guide to Ethereum Loyalty Program Development

 

Key Components

 

Owner: There is only 1 owner who deploys the contract with the authority to pick the winner.
Players: Players who enter the lottery by sending Ether of a minimum limit of 0.00001.
Winner: One of the players selected randomly to receive the total Ether collected.

 

Prerequisites:-

 

Environment Setup: Ensure you have NodeJS and npm installed.

MetaMask: Must have installed MetaMask and set up an account(For PRIVATE KEY, API KEY, and POLYGON URL).

Polygon amoy Testnet Faucet: To pay the amount of Ether for the lottery. Get some test ETH from the Polygon amoy faucet(TESTNET).

 

Also, Check | NFT-Based Loyalty Programs: Revamping Customer Engagement

 

Example:-

 

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
contract Lottery {
   address public owner;
   address payable[] public players;
   address public winner;

   constructor() {
       owner = msg.sender;
   }

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

   function enter() public payable {
       require(msg.value >= 0.00001 ether);
       players.push(payable(msg.sender));
   }
   function generateRandomNumber() public view returns (uint8) {
       return
           uint8(
               uint256(
                   keccak256(
                       abi.encodePacked(
                           block.timestamp,
                           block.prevrandao,
                           players
                       )
                   )
               ) % 251
           );
   }
   //Picking winnner using random number
   function pickWinner() public onlyOwner {
       uint256 index = generateRandomNumber() % players.length;
       //transfer reward to the winner
       players[index].transfer(address(this).balance);
       winner = players[index];
       //reset the state of the contract
       players = new address payable[](0);
   }
}   

 

Also, Read | Advancing Loyalty Programs with Hyperledger Blockchain

 

Set Version of Solidity:-


- License identifiers in Solidity smart contracts, specifically the MIT license.
- The version of the Solidity compiler in which the code is compatible with and (^) indicates that the code can be compiled with any version from 0.8.9 up to, but not including, 0.9.0.

Firstly create a contract named Lottery, containing three variable owners (who calls the contract), players as an array(which allows multiple users to stake ETH in our contract), a winner(randomly generated from one of the players).

 

Explanation of Functions:-

    
Constructor: Initializes the contract by setting the owner to the address that deployed it.

ownerFn Modifier: Ensures that only the contract owner can execute certain functions(enhancing security).

enter function: By sending a minimum amount of ETH, It Allows players to enter the lottery. The player's address is stored in the player's array.

generateRandomNumber function: Based on the current block's timestamp, the previous block's hash, and the list of players, it Generates a random pseudo-random number for selecting the winner.  

pickWinner Function: Only the owner can call this function to select a winner. It uses the random number to index into the player's array and transfers the entire balance of the contract to the winner. The player array is reset after the winner is selected.



Use the following command to run and verify that the contract has been deployed use the below command


- npx hardhat run <PATH OF SMART CONTRACT FILE> --network polygon (This command will return Lottery contract address)
- npx hardhat verify --network polygon <LOTTERY CONTRACT ADDRESS FROM PREVIOUS COMMAND>

 

Conclusion

 

In conclusion, developing a smart contract for a lottery system offers a fascinating intersection of technology, transparency, and innovation. By leveraging blockchain's immutable and decentralized nature, developers can create a lottery that is not only secure and fair but also highly efficient. The use of smart contracts ensures that the entire process—from ticket sales to prize distribution—is automated and tamper-proof, enhancing trust among participants. As we've explored, the key elements include setting up the rules, securing the contract, and ensuring the user interface is intuitive. With careful consideration and meticulous development, a blockchain-based lottery can provide an engaging and trustworthy experience for all users. Whether for entertainment or charity, smart contracts open up new possibilities for creating transparent and equitable gaming platforms. If you have a project in mind, connect with our smart contract developers to get started. 

 

Category: Blockchain
Banner

Don't just hire talent,
But build your dream team

Our experience in providing the best talents in accordance with diverse industry demands sets us apart from the rest. Hire a dedicated team of experts to build & scale your project, achieve delivery excellence, and maximize your returns. Rest assured, we will help you start and launch your project, your way – with full trust and transparency!