Latest Posts

  • How to check the type of the contract in Solidity - ERC165 explained


    Solidity does not have the concept of typeof or isinstance. Given a contract address you cannot find out if this is of a particular contract. But there is a way to do it if contract has implemented the ERC165 standard.

    ERC165 standard has just one method

    function supportsInterface(interfaceId) public view returns (bool);

    This method takes the interface id as the param and checks if the contract supports that interface. What does this mean? Solidity has in built method called type which returns the unique id of the interface. The interface you will supply here is of the contract whose type you want to check in another contract.

  • An detailed explanation of Ethereum Layer 2 Solution Polygon Matic Network [DRAFT]

    Matic is a sidechain which uses an adapted version of plasma MVP to secure itself using the Ethereum mainchain.

    Sidechain and plasma chain are 2 different concepts. Matic uses both the concepts to create a secure and scalable blockchain which is interoperable with the Ethereum main chain.

    Sidechain is another blockchain which can interact with the “parent” chain using a bridge. Sidechain is essentially a completely independent blockchain which uses pegging to enable interoperability.

    Plasma chain is another blockchain which posts root of each block to the parent chain. This is done to draw security from the a more secure blockchain. Once the block hash is store on the main chain it is considered final. The posting of the root in the parent chain is called checkpointing.

  • How to use low level call for contract function calls and payments in Solidity

    Solidity has the call function on address data type which can be used to call public and external functions on contracts. It can also be used to transfer ether to addresses.

    call is not recommended in most situations for contract function calls because it bypasses type checking, function existence check, and argument packing. It is preferred to import the interface of the contract to call functions on it.

    call is used to call the fallback and receive functions of the contract. Receive is called when no data is sent in the function call and ether is sent. Fallback function is called when no function signature matches the call.

    call consumes less gas than calling the function on the contract instance. So in some cases call is preferred for gas optimisation.

    Solidity has 2 more low level functions delegatecall and staticcall . staticcall is exactly the same as call with only difference that it cannot modify state of the contract being called. delegatecall is discussed below.

  • Nested Serializers in Django Rest Framework


    Django Rest Framework (DRF) does not handle nested json data out of the box. There is an important reason for that. DRF cannot assume how do you want it to handle the nested data. There are many possible ways to save that data or perform business logic over it. There is no defined standard way to do it. So it lets the users decide how to do it. But this freedom causes confusion among new developers.

    StackOverflow has many questions asking the how to save nested model data using a model serializer. I don’t like most of the answers given there because most of them are very complicated. DRF documentation has already given a small sample code to give a flavour of how it should be done.

  • Cosmos Network Explained - Cosmos Hub, ATOM tokens, Gravity DEX


    Cosmos is a network of interoperable blockchains. Cosmos uses Tendermint BFT which is PoS based consensus algorithm. Tendermint BFT is an open source platform and can be used by any project.

    To create a network of blockchains Cosmos provides CosmosSDK (the application layer) and Tendermint SDK (the network and consensus layer) to give complete tools to launch a public or private blockchain. All the blockchains will implement IBCI (inter blockchain communication interface) so that they can transfer tokens and data between each other seamlessly.

  • Uniswap V3 Explained - Concentrated Liquidity, Impermanent Loss, Slippage

    Uniswap protocol is an ETH native smart contract system which enables swapping of pairs of ERC20<>ERC20 and ERC20<>ETH.

    Uniswap uses automated market maker (AMM) algorithm to execute trades. Users provide liquidity in pairs of tokens to create a liquidity pool. Trades are executed by depositing the offered token in the pool and withdrawing the asked token from the pool. A swap fee is applied to the amount of ask token which is distributed to the liquidity providers (LPs).

    Uniswap V3 is the latest version of the protocol which has introduced concentrated liquidity and many other concepts. In V3 there are several fee tiers available based on the risk of providing liquidity. The fees is collected in the 2 tokens of the pool and is not invested back into the pool.

    UNI is a governance token for the Uniswap protocol. UNI token holders might be eligible for protocol fee in future. The current protocol fee is 0%. UNI token holders can change the protocol fee.

  • Bitcoin Inflation Vs Inflation

    Crypto influencers and companies use “inflation” incorrectly. “Inflation” has 2 means; the physical meaning and the economic meaning.

    • The physical meaning is the increase in size of an object.
    • The economic meaning is the decrease in purchasing power of a currency.

    Bitcoin will become deflationary (physical term) one day, which means with time total accessible supply of bitcoin will decrease. But this is will be true only when;

    number of lost bitcoins > number of mined bitcoins

    We can assume this to be true after 24 years perhaps when mining reward will be too low. But at the current time bitcoin is probably inflationary (physical term).

  • Terra blockchain and dApps explained in detail

    UPDATE (30th May 2022): Do not invest a dime in anything which Do Kwon builds.

    Terra is a PoS blockchain built using the Cosmos SDK. Cosmos SDK uses Tendermint BFT consensus mechanism which is an open source platform developed by the Cosmos team. Terra is a stable coin platform which uses Luna the base token for stabilising the price of currencies. Terra aims to bring real world assets, currencies and use cases to decentralised economy.

    This post is for educational purposes only. Not investment advice.

    Luna is the native token in Terra. Total 985M Luna are in circulation out of which almost 32% are staked. The current staking reward is 11.2% APY. (Source: Terra Station)

  • Ethereum 2.0 upgrades explained in 5 minutes

    Ethereum is facing a scaling issue because of high transaction volume. More than USD 1T were settled on Eth in 2020 and blockchain has reached its peak in terms of transactions per second. Gas fees is very high and doing a transaction on ethereum is no longer accessible for most users because of it.

    Eth 2.0 will solve the scalability issues by a combination of massive upgrades. I will summarise the new upgrades in this post. Eth 2.0 is still in development though and can take any of the numerous directions proposed by the Ethereum research team.

    Eth currently uses proof of work (PoW) as a consensus mechanism. Every 12.5s a block is produced and eth mining nodes execute smart contracts, verify the transactions and maintain the state of the blockchain.

  • SaaS Business Playbook 2020

    First decide what is your strength.

    The two main bottle necks I see in building a saas company are product and distribution.

    By product I mean what are you solving. You can build anything under the sun. But does it really provide value is a tough question to answer. The best way to answer that question is to do sales.

    Sales brings us to distribution. Distribution is basically another word for sales but there is more to it. Distribution also includes how will the user buy your product and how you will on-board the user.

  • My investment playbook 2020

    • Diversify into different markets and investment options
    • Keep 10% of capital in cash
    • When return is high, sell enough to get back the principal
    • When black swan events happen, make some hedging bets
    • Buy fixed return options like PF
    • Maintain liquidity while playing long term
    • Invest then investigate
  • How to define your customers and find them

    I have made multiple attempts at starting a successful SAAS business. This time I think I have been able to do it. I am running sumtracker, an inventory and operations management software for product brands. We are still early but I am very confident about what we are doing. We have paying customers who are happy with the service and have got real tangible results from sumtracker.

    In this post I want to talk about the genesis of a SaaS business, which is the customer. Yes, not the product or the problem. They come after we have defined who is the customer. You might get the idea first but it is not a business without the customer. In the context of a SaaS business it is important to define the problem and the customer together in the same sentence.

  • Login api using Django Rest Framework Token Authentication with Google Recaptcha and token expiry

    Django Rest Framework (DRF) is an amazing framework to create a REST API. It has token based auth built in to create a login api. I have used the code from DRF to create a more feature rich login API.

    I have added:

    • Token caching till the user logs out
    • Time based token expiry
    • Logout api
    • Google recaptcha support
    • password change token expiry
    • Saving the last login time
  • Finding product market fit in a SaaS business idea involves cracking 3 things

    These are important to make sure you don’t fail. In my experience of trying to build a SaaS company I failed twice on all 3 aspects. I didn’t iterate on these enough to discover product market fit (PMF). I am currently in my 3rd attempt to built a SaaS company and this time I am focused to get it right. Product market fit is when you know who to sell, what to sell and how to sell.

    • Customer definition and understanding
    • State what are you solving
    • Differentiation
  • Building the future at Ethereum DevCon2

    Ethereum devcon2 2016 was held in Shanghai and was organised by the Ethereum foundation. The event spanned 3 days from 19th to 21st September in the Grand ballroom at Hyatt on the bund.

    My overall experience of attending the devcon was awesome. I had never been to such a conference and didn’t know what happened there and what is the agenda of the people coming to these conferences. It seems the agenda was pretty straightforward for the attendees; networking. There were primarily 2 kinds of presentations; from the Ethereum foundation and from various projects and startups building on Ethereum platform. For the presenters the agenda was announcing updates and marketing.