<?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: rahuldev-17</title>
    <description>The latest articles on DEV Community by rahuldev-17 (@rahuldev17).</description>
    <link>https://dev.to/rahuldev17</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%2F780533%2F27a01b5b-2381-4c9f-92bb-bc6821523362.PNG</url>
      <title>DEV Community: rahuldev-17</title>
      <link>https://dev.to/rahuldev17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rahuldev17"/>
    <language>en</language>
    <item>
      <title>Miscellaneous Tips</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Fri, 03 Nov 2023 12:00:03 +0000</pubDate>
      <link>https://dev.to/rahuldev17/miscellaneous-tips-31jp</link>
      <guid>https://dev.to/rahuldev17/miscellaneous-tips-31jp</guid>
      <description>&lt;h2&gt;
  
  
  How to get vim to use another vimrc file
&lt;/h2&gt;

&lt;p&gt;Vim will use the ~/.vimrc by default. If you wish to specify another initialization script, just do:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;vim -u &amp;lt;PATH TO FILE&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where is my .vimrc file?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;:echo $VIM&lt;/code&gt;&lt;br&gt;
&lt;code&gt;:echo $MYVIMRC&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  OSError - Errno 13 Permission denied
&lt;/h2&gt;

&lt;p&gt;run id in the terminal to get your user_id and group_id&lt;/p&gt;

&lt;p&gt;Go the directory/partition where you are facing the challenge. Open terminal, type id then press enter. This will show you your user_id and group_id&lt;/p&gt;

&lt;p&gt;then type&lt;br&gt;
&lt;code&gt;chown -R user-id:group-id .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Replace user-id and group-id&lt;/p&gt;

&lt;p&gt;. at the end indicates current partition / repository&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chown -R 1001:1001 .&lt;/code&gt;&lt;br&gt;
(that was my case)&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I run .sh scripts?
&lt;/h2&gt;

&lt;p&gt;Give execute permission to your script:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;chmod +x /path/to/yourscript.sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And to run your script:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/path/to/yourscript.sh&lt;/code&gt;&lt;br&gt;
Since . refers to the current directory: if yourscript.sh is in the current directory, you can simplify this to:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;./yourscript.sh&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  check file size
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ls -sh&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;stat file&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>nix VPS running out of memory?</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Sun, 23 Jul 2023 05:22:14 +0000</pubDate>
      <link>https://dev.to/rahuldev17/nix-vps-running-out-of-memory-3aba</link>
      <guid>https://dev.to/rahuldev17/nix-vps-running-out-of-memory-3aba</guid>
      <description>&lt;p&gt;Note to me: If your VPS is running out memory while installing another application, then quick fix:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;check disk usage:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$df -h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;find files greater than 500MB
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo find / -type f -size +500M -exec ls -lh {} \;

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

&lt;/div&gt;



&lt;p&gt;If you understand and are sure of what files are not being used by you, database or system, remove them.  &lt;/p&gt;

</description>
      <category>linux</category>
      <category>system</category>
    </item>
    <item>
      <title>Where is RouteServiceProvider code in Laravel codes?</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Sat, 22 Jul 2023 09:49:12 +0000</pubDate>
      <link>https://dev.to/rahuldev17/-where-is-routeserviceprovider-code-in-laravel-codes-113j</link>
      <guid>https://dev.to/rahuldev17/-where-is-routeserviceprovider-code-in-laravel-codes-113j</guid>
      <description>&lt;p&gt;So.. while reading &lt;a href="https://laravel.com/docs/10.x/lifecycle"&gt;Laravel documentation&lt;/a&gt;, did you wonder the same? if yes, here you go:&lt;br&gt;
 The RouteServiceProvider code in Laravel is located in the &lt;code&gt;app/Providers/RouteServiceProvider.php&lt;/code&gt; file. This file is responsible for registering the application's routes and middleware. It also defines the default namespace for controller routes.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to find the RouteServiceProvider code
&lt;/h2&gt;

&lt;p&gt;To find the RouteServiceProvider code in your Laravel project,navigate to &lt;code&gt;app&lt;/code&gt;/&lt;code&gt;Providers&lt;/code&gt;/ and open &lt;code&gt;RouteServiceProvider.php&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;but you need more help so...&lt;/p&gt;
&lt;h2&gt;
  
  
  The RouteServiceProvider code
&lt;/h2&gt;

&lt;p&gt;The RouteServiceProvider code is divided into two main sections:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;boot()&lt;/code&gt; method: This method registers the application's routes and middleware.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;map()&lt;/code&gt; method: This method defines the default namespace for controller routes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  The &lt;code&gt;boot()&lt;/code&gt; method
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;boot()&lt;/code&gt; method uses the &lt;code&gt;Route&lt;/code&gt; facade to register the application's routes. The &lt;code&gt;Route&lt;/code&gt; facade provides a number of methods for registering routes, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;get()&lt;/code&gt;: Registers a GET route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;post()&lt;/code&gt;: Registers a POST route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;put()&lt;/code&gt;: Registers a PUT route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;delete()&lt;/code&gt;: Registers a DELETE route.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  The &lt;code&gt;map()&lt;/code&gt; method
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;map()&lt;/code&gt; method defines the default namespace for controller routes. The default namespace is the namespace that is used to prefix controller route declarations. For example, if the default namespace is &lt;code&gt;App\Http\Controllers&lt;/code&gt;, then the following route declaration would route requests to the &lt;code&gt;HomeController&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'HomeController@index'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The &lt;code&gt;RouteServiceProvider&lt;/code&gt; code is a critical part of the Laravel framework.
&lt;/h2&gt;

&lt;p&gt;It is responsible for registering the application's routes and middleware, and it also defines the default namespace for controller routes.&lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to go deep in ethers one function at a time: ParseUnits()</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Mon, 10 Jan 2022 18:57:58 +0000</pubDate>
      <link>https://dev.to/rahuldev17/dissecting-ethers-one-function-at-a-time-parseunits-3m7m</link>
      <guid>https://dev.to/rahuldev17/dissecting-ethers-one-function-at-a-time-parseunits-3m7m</guid>
      <description>&lt;p&gt;Time to get familiar with your tool-set. Okay, so how does Ricmoo write his js/ts functions? Let us see ParseUnits().&lt;/p&gt;

&lt;p&gt;It is written in Typescript at &lt;code&gt;ethers.js/packages/units/src.ts/index.ts&lt;/code&gt;. Here it goes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function parseUnits(value: string, unitName?: BigNumberish): BigNumber {
    if (typeof(value) !== "string") {
        logger.throwArgumentError("value must be a string", "value", value);
    }
    if (typeof(unitName) === "string") {
        const index = names.indexOf(unitName);
        if (index !== -1) { unitName = 3 * index; }
    }
    return parseFixed(value, (unitName != null) ? unitName: 18);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function takes two arguements and one is strigified value, and another 'unitname'. This function is kind of checker, meat is in 'parseFixed' function. And we see that this function is taken from:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import { formatFixed, parseFixed } from "@ethersproject/bignumber";&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;From 'bignumber', we get to know it is coming from 'fixednumber':&lt;/p&gt;

&lt;p&gt;&lt;code&gt;export { formatFixed, FixedFormat, FixedNumber, parseFixed } from "./fixednumber";&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;export function parseFixed(value: string, decimals?: BigNumberish): BigNumber {

    if (decimals == null) { decimals = 0; }
    const multiplier = getMultiplier(decimals);

    if (typeof(value) !== "string" || !value.match(/^-?[0-9.]+$/)) {
        logger.throwArgumentError("invalid decimal value", "value", value);
    }

    // Is it negative?
    const negative = (value.substring(0, 1) === "-");
    if (negative) { value = value.substring(1); }

    if (value === ".") {
        logger.throwArgumentError("missing value", "value", value);
    }

    // Split it into a whole and fractional part
    const comps = value.split(".");
    if (comps.length &amp;gt; 2) {
        logger.throwArgumentError("too many decimal points", "value", value);
    }

    let whole = comps[0], fraction = comps[1];
    if (!whole) { whole = "0"; }
    if (!fraction) { fraction = "0"; }

    // Trim trailing zeros
    while (fraction[fraction.length - 1] === "0") {
        fraction = fraction.substring(0, fraction.length - 1);
    }

    // Check the fraction doesn't exceed our decimals size
    if (fraction.length &amp;gt; multiplier.length - 1) {
        throwFault("fractional component exceeds decimals", "underflow", "parseFixed");
    }

    // If decimals is 0, we have an empty string for fraction
    if (fraction === "") { fraction = "0"; }

    // Fully pad the string with zeros to get to wei
    while (fraction.length &amp;lt; multiplier.length - 1) { fraction += "0"; }

    const wholeValue = BigNumber.from(whole);
    const fractionValue = BigNumber.from(fraction);

    let wei = (wholeValue.mul(multiplier)).add(fractionValue);

    if (negative) { wei = wei.mul(NegativeOne); }

    return wei;
}

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

&lt;/div&gt;



&lt;p&gt;Hope now you understand where is the real body after all the check. If no, here it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const wholeValue = BigNumber.from(whole);
    const fractionValue = BigNumber.from(fraction);

    let wei = (wholeValue.mul(multiplier)).add(fractionValue);

    if (negative) { wei = wei.mul(NegativeOne); }

    return wei;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, Bignumber library is used to convert whole and fraction parts of value into into 'bignumber', and then they are added. So all ether calculation is 'wei' in ethers. &lt;/p&gt;

&lt;p&gt;But from where the 'Bignumber' is coming? It is coming from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { BigNumber, BigNumberish, isBigNumberish } from "./bignumber";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lol, it is coming from 'bignumber'.&lt;/p&gt;

&lt;p&gt;From there, we get to know it is wrapper around 'BN.js' library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 *  BigNumber
 *
 *  A wrapper around the BN.js object. We use the BN.js library
 *  because it is used by elliptic, so it is required regardless.
 *
 */

import _BN from "bn.js";
import BN = _BN.BN;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you still want to go deeper than that. Bravo. Here we go. The 'from' method is written by Ricmoo/team&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; static from(value: any): BigNumber {
        if (value instanceof BigNumber) { return value; }

        if (typeof(value) === "string") {
            if (value.match(/^-?0x[0-9a-f]+$/i)) {
                return new BigNumber(_constructorGuard, toHex(value));
            }

            if (value.match(/^-?[0-9]+$/)) {
                return new BigNumber(_constructorGuard, toHex(new BN(value)));
            }

            return logger.throwArgumentError("invalid BigNumber string", "value", value);
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are still here, understand going below beyond this will push you outside the dev zone of application layer, you will go into decimal conversion mathematics. Your choose!&lt;/p&gt;

&lt;p&gt;like it? Then, don't forget to give heart!&lt;/p&gt;

</description>
      <category>ethers</category>
      <category>bignumber</category>
      <category>codereview</category>
    </item>
    <item>
      <title>How to sell a token programmatically</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Wed, 05 Jan 2022 18:27:14 +0000</pubDate>
      <link>https://dev.to/rahuldev17/how-to-sell-a-token-programmatically-58o</link>
      <guid>https://dev.to/rahuldev17/how-to-sell-a-token-programmatically-58o</guid>
      <description>&lt;p&gt;If you want to sell a token on Binance Smart Chain (BSC) via a script, we present a complete program. You can use the script easily for other EVM compatible blockchains just by modifying the addresses for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;native coin&lt;/li&gt;
&lt;li&gt;router&lt;/li&gt;
&lt;li&gt;desired token address&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;MOST IMPORTANT: USE AN ACCOUNT WITH JUST NOMINAL VALUE OF BNB SUCH AS 0.01 BNB WHICH YOU CAN AFFORD TO LOSE. I cannot overemphasis it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I assume that you have experience with basic nodejs programming, and you have installed 'metamask' wallet, and know the seed phrase of your wallet. Further, assuming you already have purchased the token(to purchase token programmatically read this &lt;a href="https://dev.to/rahuldev17/how-to-buy-a-token-programmatically-3plb"&gt;https://dev.to/rahuldev17/how-to-buy-a-token-programmatically-3plb&lt;/a&gt; ), here are the steps to sell a token programmatically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a project folder&lt;/li&gt;
&lt;li&gt;create a .env file in your project folder&lt;/li&gt;
&lt;li&gt;Write your private information in the .env file; do not enclose info in ""; save the file&lt;/li&gt;
&lt;li&gt;create another file in the same project folder, and copy paste the 'sellToken.js' script&lt;/li&gt;
&lt;li&gt;Put the token address you want to sell for in this file.&lt;/li&gt;
&lt;li&gt;execute the script&lt;/li&gt;
&lt;li&gt;I have not handled 'returned promise rejections' in this program. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If it is your first time of selling of this token, do approve the token for swapping via 'metamask' if not done beforehand, otherwise you might not be able to sell the token.&lt;/p&gt;

&lt;p&gt;'.env' file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MNEMONIC=
MY_ACCOUNT_ADDRESS=
GET_BLOCK_API_KEY=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'sellToken.js' script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ethers = require('ethers');
require('dotenv').config()

const addresses = {
    WBNB: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",// native coin
    router:"0x10ED43C718714eb63d5aA57B78B54704E256024E", // PCS router

    recipient: process.env.MY_ACCOUNT_ADDRESS, //metamask acccount address
    tokenAddress:"" // token address you are interested in 
}


const mnemonic = process.env.MNEMONIC // seed phrase for Metamask 
const mygasPrice = ethers.utils.parseUnits('10', 'gwei');// setting gas price


const provider = new ethers.providers.WebSocketProvider("wss://bsc.getblock.io/testnet/?api_key=" + process.env.GET_BLOCK_API_KEY);
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
const account = wallet.connect(provider);

var amount; 

const router = new ethers.Contract(
  addresses.router,
  [
  'function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline)',
      'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)     external     payable     returns (uint[] memory amounts)',
    'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'

  ],
  account
);


const sell = async () =&amp;gt; {


    let tokenIn = addresses.tokenAddress , tokenOut = addresses.WBNB;

    const amountIn = ethers.utils.parseUnits("1.0",9); //selling one token with 9 decimals; change decimals to 18 if desired
    const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
    //let us be ready to accept little less of BNB due to price fluctuations
    const amountOutMin = amounts[1].sub(amounts[1].div(10));

    console.log(`
      selling new token
      =================
      tokenIn: ${amountIn} ${tokenIn}
      tokenOut: ${amountOutMin} ${tokenOut} (WBNB)
    `);

    const tx = await router.swapExactTokensForETH(
      amountIn,
      amountOutMin,
      [tokenIn, tokenOut],
      addresses.recipient,
      Math.floor(Date.now() / 1000) + 60 * 15, // 15 minutes from the current Unix time
      {
          gasPrice: mygasPrice,
          gasLimit: 250000
      }
    );

    const receipt = await tx.wait(); 
    console.log('Transaction receipt');
    console.log(receipt);
  }

sell();


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

&lt;/div&gt;



&lt;p&gt;Hope you find this useful. If so, give love and share.&lt;/p&gt;

</description>
      <category>bsc</category>
      <category>etherjs</category>
      <category>token</category>
      <category>sell</category>
    </item>
    <item>
      <title>How to buy a token programmatically</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Wed, 05 Jan 2022 17:36:21 +0000</pubDate>
      <link>https://dev.to/rahuldev17/how-to-buy-a-token-programmatically-3plb</link>
      <guid>https://dev.to/rahuldev17/how-to-buy-a-token-programmatically-3plb</guid>
      <description>&lt;p&gt;If you want to buy a token on Binance Smart Chain (BSC) via a script, we present a complete program. You can use the script easily for other EVM compatible blockchains just by modifying the addresses for:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;native coin&lt;/li&gt;
&lt;li&gt;router and factory&lt;/li&gt;
&lt;li&gt;desired token address&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;MOST IMPORTANT: USE AN ACCOUNT WITH JUST NOMINAL VALUE OF BNB SUCH AS 0.01 BNB WHICH YOU CAN AFFORD TO LOSE. I cannot overemphasis it.&lt;/p&gt;

&lt;p&gt;Assuming you have experience with basic nodejs programming, and you have installed 'metamask' wallet, and know the seed phrase, here are the steps to buy a token programmatically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a project folder &lt;/li&gt;
&lt;li&gt;create a .env file in your project folder&lt;/li&gt;
&lt;li&gt;Write your private information in the .env file; do not enclose info in ""; save the file&lt;/li&gt;
&lt;li&gt;create another file in the same project folder, and copy paste the 'buyToken.js' script&lt;/li&gt;
&lt;li&gt;Put the token address you want to purchase for in this file. &lt;/li&gt;
&lt;li&gt;execute the script &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I have not handled 'returned promise rejections' in this program. If it is your first purchase of the token, do import the token in 'metamask' if not done beforehand, otherwise you might not see the token in your account. &lt;/p&gt;

&lt;p&gt;'.env' file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MNEMONIC=
MY_ACCOUNT_ADDRESS=
GET_BLOCK_API_KEY=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;'buyToken.js' script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ethers = require('ethers');
require('dotenv').config()

const addresses = {
    WBNB: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",// native coin
    router:"0x10ED43C718714eb63d5aA57B78B54704E256024E", // PCS router
    recipient: process.env.MY_ACCOUNT_ADDRESS, //metamask acccount address
    tokenAddress:"" // token address you are interested in 
}


const mnemonic = process.env.MNEMONIC // seed phrase for Metamask 
const mygasPrice = ethers.utils.parseUnits('10', 'gwei');// setting gas price


const provider = new ethers.providers.WebSocketProvider("wss://bsc.getblock.io/testnet/?api_key=" + process.env.GET_BLOCK_API_KEY);
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
const account = wallet.connect(provider);

var amount; 

const router = new ethers.Contract(
  addresses.router,
  [
  'function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline)',
      'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)     external     payable     returns (uint[] memory amounts)',
    'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'

  ],
  account
);


  const buy = async () =&amp;gt; {

  let tokenIn = addresses.WBNB , tokenOut = addresses.tokenAddress;

  const amountIn = ethers.utils.parseUnits('0.0001', 'ether'); // Most Important.. swapping only 0.0001 BNB, change this value if desired
  const amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut]);
  // accepting a little lower amount 
  const amountOutMin = amounts[1].sub(amounts[1].div(10));

  // to be used later while selling : amount = amountOutMin;

  console.log(`
    Buying new token
    =================
    tokenIn: ${amountIn} ${tokenIn} (WBNB)
    tokenOut: ${amountOutMin} ${tokenOut}
  `);

   const tx = await router.swapExactETHForTokens( 
    amountOutMin,
    [tokenIn, tokenOut],
    addresses.recipient,
    Math.floor(Date.now() / 1000) + 60 * 15, // 15 minutes from the current Unix time
    {
        gasPrice: mygasPrice,
        gasLimit: 270000, 
        value: amountIn // important for exact ethereum amount
    },

  );
  const receipt = await tx.wait(); 
  console.log('Transaction receipt');
  console.log(receipt); 
}
buy();

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

&lt;/div&gt;



&lt;p&gt;Hope you find this useful. If so, give love and share. &lt;/p&gt;

</description>
      <category>bsc</category>
      <category>etherjs</category>
      <category>token</category>
      <category>buy</category>
    </item>
    <item>
      <title>How to deploy a solidity contract with etherjs</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Wed, 29 Dec 2021 16:40:05 +0000</pubDate>
      <link>https://dev.to/rahuldev17/how-to-deploy-a-solidity-contract-with-etherjs-4n5c</link>
      <guid>https://dev.to/rahuldev17/how-to-deploy-a-solidity-contract-with-etherjs-4n5c</guid>
      <description>&lt;p&gt;Assuming you have installed metamask, and know the seed phrase, here are steps to deploy contract using 'ethers' and 'fs':&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;compile the contract to .bin and .abi files&lt;/li&gt;
&lt;li&gt;load 'ethers' and 'fs'&lt;/li&gt;
&lt;li&gt;create a 'signer' object using 'provider', 'Wallet', and 'connect' methods from 'ethers'&lt;/li&gt;
&lt;li&gt;create a contract instance from 'ContractFactory' method&lt;/li&gt;
&lt;li&gt;use deploy method as promise&lt;/li&gt;
&lt;li&gt;Here I have used 'getblock' as web3 provider for example (see &lt;a href="https://getblock.io/docs/get-started/auth-with-api-key/"&gt;https://getblock.io/docs/get-started/auth-with-api-key/&lt;/a&gt;). Other alternatives are 'quicknode', 'alchemy' and 'infura'.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We will deploy the code to the BSC testnet, but same procedure will apply for other Ethereum Virtual Machine(EVM) compatible chains, such as : Avalanche Contract Chain (C-Chain), Binance Smart Chain (BSC) mainnet, Fantom Opera and Polygon etc.&lt;/p&gt;

&lt;p&gt;nodejs script for contract deployment goes here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//load 'ethers' and 'fs'

ethers = require('ethers');
fs = require('fs');

//Read bin and abi file to object; names of the solcjs-generated files renamed
bytecode = fs.readFileSync('storage.bin').toString();
abi = JSON.parse(fs.readFileSync('storage.abi').toString());

//to create 'signer' object;here 'account'
const mnemonic = "&amp;lt;see-phrase&amp;gt;" // seed phrase for your Metamask account
const provider = new ethers.providers.WebSocketProvider("wss://bsc.getblock.io/testnet/?api_key=&amp;lt;your-api-key&amp;gt;");
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
const account = wallet.connect(provider);

const myContract = new ethers.ContractFactory(abi, bytecode, account);

//Using 'deploy method 'in 'async-await' 
async function main() {
// If your contract requires constructor args, you can specify them here
const contract = await myContract.deploy();

console.log(contract.address);
console.log(contract.deployTransaction);
}

main();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, 'account' is the 'signer' of the ethers docs &lt;a href="https://dev.tourl"&gt;&lt;br&gt;
https://docs.ethers.io/v5/api/contract/contract-factory/#ContractFactory--creating&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ethers.ContractFactory( interface , bytecode [ , signer ] )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not hesitate to ask in discussion if you face any problem in deploying your contract. &lt;/p&gt;

</description>
      <category>solidity</category>
      <category>deploy</category>
      <category>ethers</category>
      <category>web3</category>
    </item>
    <item>
      <title>How to understand long contracts with a visual tool: Sol2Uml</title>
      <dc:creator>rahuldev-17</dc:creator>
      <pubDate>Sun, 26 Dec 2021 03:04:08 +0000</pubDate>
      <link>https://dev.to/rahuldev17/a-visual-tool-to-understand-long-contracts-sol2uml-257i</link>
      <guid>https://dev.to/rahuldev17/a-visual-tool-to-understand-long-contracts-sol2uml-257i</guid>
      <description>&lt;p&gt;Have you ever faced difficulty in understanding a large solidity contract? If you answer in affirmative, you are in good company. Commercially deployed contracts on mainnet typically runs in ~800 to 1000 LOC. To wrap your brain around the whole contract just by scrolling might not be so useful. So let us explore a visual aid for this purpose: "Solidity to UML".&lt;/p&gt;

&lt;p&gt;Let us first see its example on &lt;a href="https://bscscan.com/address"&gt;BSC scan&lt;/a&gt; (blockchain explorer-mainnet). On the contract page, click the on the "outline" button to get an overview of different interfaces, library and available abstract contracts(zoom in the image for clarity). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I7SP-hlz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvptzdpzeo5apl4npm0u.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I7SP-hlz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvptzdpzeo5apl4npm0u.JPG" alt="verified contract tab on BSC scan " width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get a visual representation click on the  "more options" dropdown list, and click on the "Sol2Uml" button(zoom in the image for clarity).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZuHibaWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c3hkthc8j2sgv2s1nff.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZuHibaWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c3hkthc8j2sgv2s1nff.JPG" alt="verified contract tab on BSC scan" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A vector file(SVG) is generated which can be zoomed infinitely to view the call diagrams between class like structures of your contracts. &lt;/p&gt;

&lt;p&gt;You can also use it to view contracts in your local environment by installing it as npm package. See details &lt;a href="https://github.com/naddison36/sol2uml"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Comment or ask if any further queries down below the box.&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>contract</category>
      <category>sol2uml</category>
      <category>visualaid</category>
    </item>
  </channel>
</rss>
