<?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: Tamal Sen</title>
    <description>The latest articles on DEV Community by Tamal Sen (@tamalsen2509).</description>
    <link>https://dev.to/tamalsen2509</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%2F818286%2Fed9b201a-ef66-4c02-b6fc-0b9fada2c60b.jpeg</url>
      <title>DEV Community: Tamal Sen</title>
      <link>https://dev.to/tamalsen2509</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tamalsen2509"/>
    <language>en</language>
    <item>
      <title>Angular DAPPS. How to connect Angular with Deployed Smart Contract?</title>
      <dc:creator>Tamal Sen</dc:creator>
      <pubDate>Sun, 21 Aug 2022 08:48:31 +0000</pubDate>
      <link>https://dev.to/tamalsen2509/angular-dapps-how-to-connect-angular-with-deployed-smart-contract-khg</link>
      <guid>https://dev.to/tamalsen2509/angular-dapps-how-to-connect-angular-with-deployed-smart-contract-khg</guid>
      <description>

&lt;p&gt;Hello to all my beautiful reader and to those who are learning to code.In this writing I am going to share how to create a web3 front-end application in Angular and connect with deployed smart contract . &lt;br&gt;
Readers are going to discover the procedures and npm package name to do the work done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites &lt;/strong&gt;&lt;br&gt;
Basics of Angular framework .&lt;br&gt;
Basic of Solidity Programming Language.&lt;br&gt;
Basic of Blockchain and Smart Contract.&lt;br&gt;
Beginner level of knowledge in OOP.&lt;/p&gt;

&lt;p&gt;I personally want to give a huge shout out to LearnWeb3Dao to make learning block chain so easy thorough step by step process with structured practical based learning methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Smart Contract will Do ?  &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this section i am going to share the code for smart contract, what this smart contract does , is allowing any metamask wallet to have an entry into Whitelist Object , and set a boolean flag to true . Based on the whitelist addresses any future business decisions can be taken. Or in other point this Whitelist smart contract is replication of a database model , which will hold the wallet address to have an early bird access .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2AkNTKFp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b24nsvlvi6qydl6hwwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2AkNTKFp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b24nsvlvi6qydl6hwwi.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our smart contract is ready to be deployed.After compilation process done , we need two variables through which we can connect smart contract with frontend application ,these  are a contract &lt;a href="https://github.com/tamalsen2509/frontend_whitelist_by_learn_web3/blob/feature/src/connection/ABI.ts"&gt;ABI&lt;/a&gt; and smart contract &lt;a href="https://github.com/tamalsen2509/frontend_whitelist_by_learn_web3/blob/feature/src/connection/address.ts"&gt;address&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Part integration with Angular Application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5xVsaS9h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69r7uxrkdkv9hid64s77.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5xVsaS9h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/69r7uxrkdkv9hid64s77.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To follow the integration process we need to install &lt;a href="https://docs.ethers.io/v5/"&gt;ethers&lt;/a&gt; package in our angular apps , use angular cli command and run npm i ethers . In angular component import ethers and follow below code to begin . To change a state of a smart contract we need 2 object or classes provider &amp;amp; signer&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cX_qEEuA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkfk9xra068m71nl2a9v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cX_qEEuA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkfk9xra068m71nl2a9v.png" alt="Image description" width="880" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;declare the function name connecToWallet() and call the function inside ngOnit , so that once the component will load , the function will fire and connect to metamask wallet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change the State of smart contract /call Add into whitelist function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add a wallet address in whitelist contract please declare a function as per the example code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  async connectContract() { // function bind with click event 
    // method to enter details in smart contract
    try { // all we need an abi file and deployed smart contract address;
      this.whitelistContract = new ethers.Contract(ADDRESS_WHITELIST, WhitelistABI.abi, this.signer)
      const tx = await this.whitelistContract.addAddresstoWhiteList() // declare transaction 
      await tx.wait();

    } catch (error: any) {


      // console.log(error.message)
      this.isError = this.fetchStringContent(error.message)


    }

  }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Call the function to return the total number of contract white listed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To know, the current count of whitelist address, we need to call , Whitelist.numAddressesWhitelisted variable from solidity file ; Please follow the code as per screen shot;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  async getNumberofWhiteList() {

    try {
      this.whitelistContract = new ethers.Contract(ADDRESS_WHITELIST, WhitelistABI.abi, this.signer)
      this.whiteListNumbers = await this.whitelistContract.numAddressesWhitelisted()


    } catch (error) {
      console.log(error)
    }


  }

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

&lt;/div&gt;



&lt;p&gt;All this we need to create a front end dapps with angular , adding more convenience , I am going to share the &lt;a href="https://github.com/tamalsen2509/frontend_whitelist_by_learn_web3"&gt;repository&lt;/a&gt; details , so that you can download and play around with existing code base;&lt;/p&gt;

&lt;p&gt;Before leaving just want to share one wisdom , to learn new technology or skills , takes time to grasp. Hence just try to give yourself 30 mins everyday to practice , have faith on yourself and enjoy the process.&lt;/p&gt;

&lt;p&gt;If you have any feedback on this article please share trough comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thinking of hiring&lt;/strong&gt; my team for your next &lt;strong&gt;agile development project&lt;/strong&gt;, write me at &lt;a href="mailto:tamal.sen@outlook.com"&gt;tamal.sen@outlook.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>angular</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
