<?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: Abdulhafiz</title>
    <description>The latest articles on DEV Community by Abdulhafiz (@abdhafizahmed).</description>
    <link>https://dev.to/abdhafizahmed</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%2F86139%2Fe0f9e10e-e771-461f-8693-981fa3992d8c.jpg</url>
      <title>DEV Community: Abdulhafiz</title>
      <link>https://dev.to/abdhafizahmed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdhafizahmed"/>
    <language>en</language>
    <item>
      <title>Operating Multichain tokens on a unilateral token bridge (BSC &lt;&gt; SOLANA)</title>
      <dc:creator>Abdulhafiz</dc:creator>
      <pubDate>Thu, 14 Mar 2024 04:44:11 +0000</pubDate>
      <link>https://dev.to/abdhafizahmed/operating-multichain-tokens-on-a-unilateral-token-bridge-bsc-solana-42la</link>
      <guid>https://dev.to/abdhafizahmed/operating-multichain-tokens-on-a-unilateral-token-bridge-bsc-solana-42la</guid>
      <description>&lt;p&gt;It's almost like we hear of new blockchains every other day now and they are often architecturally incompatible. It could be overwhelming to keep up with the technological innovation.&lt;/p&gt;

&lt;p&gt;Luckily, tools are constantly being created to match the requirements of clients so that developers can make their technical wishes come true (at least before we are all replaced by AI 🤖 👨🏾‍💻) &lt;/p&gt;

&lt;p&gt;In this article, I am going to show you can build a conceptual token bridge that achieves 1:1 parity between tokens on Binance Smart Chain (BSC) and Solana Blockchain. &lt;/p&gt;

&lt;h2&gt;
  
  
  Considerations:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;- Token Name and Token Symbol&lt;/strong&gt;&lt;br&gt;
Since we will work with the assumption that this token is owned by the same project, I've the same name and symbol to represent both. The token name is "Useless Token" and symbol is "USELESS".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Token Standard&lt;/strong&gt;&lt;br&gt;
USELESS (BSC) version will be BEP20&lt;br&gt;
USELESS (Solana) token will be SPL-20&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Smart contracts&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;USELESS (BSC) will be designed using &lt;a href="https://docs.openzeppelin.com/contracts/5.x/erc20"&gt;Openzeppelin's library&lt;/a&gt; and deployed via remix&lt;/li&gt;
&lt;li&gt;USELESS (Solana) will be deployed to the blockchain using &lt;a href="https://metaboss.rs"&gt;Metaboss tool&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;- Token Interaction&lt;/strong&gt;&lt;br&gt;
USELESS (BSC) will be interacted with using &lt;a href="https://docs.ethers.io"&gt;Ethers.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;USELESS (Solana) will be interacted with using &lt;a href="https://www.npmjs.com/package/@solana/web3.js"&gt;Solana Web3 Javascript SDK&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/@solana/spl-token"&gt;Solana Token Program Library&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Creating USELESS (Solana) token deploying it on solana chain.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first step to do this is to &lt;a href="https://solana.com/developers/guides/getstarted/setup-local-development#3-install-the-solana-cli"&gt;install solana-cli&lt;/a&gt;.&lt;br&gt;
I used the command &lt;br&gt;
&lt;code&gt;solana-keygen grind --starts-with use:1 --ignore-case&lt;/code&gt; to create a vanity address keypair with the "use" prefix because I think it's sounds cool since our token will be "USE-less". It generated the address &lt;a href="https://solscan.io/account/uSEZwk76nxzBCbbPzD9Yc191wYdkQu5wN8GmV7p5zSo"&gt;uSEZ...5zSo&lt;/a&gt; and its keypair will be saved in the working directory, I sent some SOL to it from another wallet which will be used for transaction fees later.&lt;/p&gt;

&lt;p&gt;I created my token metadata and stored it on gitlab as a snippet, then stored it on gitlab as a &lt;a href="https://gitlab.com/-/snippets/3686959/raw/main/useless.json"&gt;snippet&lt;/a&gt; although it is advisable to store metadata on immutable storages like &lt;a href="https://arweave.org"&gt;arweave&lt;/a&gt;. Regarding the token metadata json structure, you can read more about the different token standards well-explained on &lt;a href="https://developers.metaplex.com/token-metadata/token-standard"&gt;metaplex's website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By using metaboss, you need to create another metadata file in the directory you are working from with the fields "name", "symbol" and "uri". This uri must point to the raw token standard metadata file hosted on arweave or in this case, gitlab's snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "name": "Useless Token",
    "symbol": "USELESS",
    "uri": "https://gitlab.com/-/snippets/3686959/raw/main/useless.json"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AGAIN: You will create two metadata files: one that conforms with that of the spl-token &lt;a href="https://developers.metaplex.com/token-metadata/token-standard"&gt;token standard&lt;/a&gt; that would be stored in an immutable storage, and another one (above) to be used while creating our token below.&lt;/p&gt;

&lt;p&gt;Since, I have both keypair and the "metadata pointer" files in the same directory, I used this command to mint a new token with 100m supply and 9 decimals.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;metaboss create fungible -k uSEZwk76nxzBCbbPzD9Yc191wYdkQu5wN8GmV7p5zSo.json -d 9 --initial-supply 100000000 -m token.json -r https://api.mainnet-beta.solana.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The token minted successfully.&lt;/p&gt;

&lt;p&gt;Note: If you get the error &lt;code&gt;Error: RPC response error -32002: Transaction simulation failed: Blockhash not found&lt;/code&gt;, just keep trying or try other node endpoints like &lt;a href="https://account.getblock.io/sign-in?ref=MTE5MDQ2YWQtM2JmNi01N2FlLWE1ZmYtYjhjNWZiM2ExZjEw"&gt;getblock.io&lt;/a&gt; with my affiliate link (thank you).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scripting with &lt;del&gt;NodeJS&lt;/del&gt; Bun
I am beginning to prefer Bun because of its native typescript support, so I used bun to initialize my project and installed necessary dependencies
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bunx init
bun add @solana/web3.js
bun add @solana/spl-token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I created a file "useless.ts" and added the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// useless.ts
import { PublicKey, Connection, clusterApiUrl, Keypair, Transaction, sendAndConfirmTransaction } from '@solana/web3.js'
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID, createTransferCheckedInstruction } from '@solana/spl-token'

const connection = new Connection(clusterApiUrl('mainnet-beta'), 'confirmed') // connection to mainnet
const secretKeyArray = await Bun.file('./uSEZwk76nxzBCbbPzD9Yc191wYdkQu5wN8GmV7p5zSo.json').json() // generated key is in the same directory as this file
const secretKey = Uint8Array.from(secretKeyArray);
const signer = Keypair.fromSecretKey(secretKey); // derived signer https://solana.com/docs/clients/javascript#quickstart


const decimals = 9 // token decimals during token creation
const uselessTokenAddressSPL = '6QWe8neoMdYUcv7LRnaBguVHTEKxC59j6Fhw8XT2pxqW' // address generated after token was minted
const mySOLWalletAddress = 'uSEZwk76nxzBCbbPzD9Yc191wYdkQu5wN8GmV7p5zSo'

// function to send solana token to given receiver and amount 
const sendSolanaToken = async (solReceiver: string, amount: number) =&amp;gt; {
  const uselessToken = new PublicKey(uselessTokenAddressSPL)
  const mySOLWallet = new PublicKey(mySOLWalletAddress)
  const receiver = new PublicKey(solReceiver)

  // this is important because solana spl-tokens use different accounts
  // to hold tokens for different wallets, so if the receiving account
  // doesn't already have an associated account for this token, we will have to create it for them
  // so that they can receive it (Read more at https://spl.solana.com/token#example-transferring-tokens-to-another-user)
  const fromAccount = await getOrCreateAssociatedTokenAccount(connection, signer, uselessToken, mySOLWallet)
  const toAccount = await getOrCreateAssociatedTokenAccount(connection, signer, uselessToken, receiver)

  try {
    // to ensure we are attempting to add our transaction after a previously finalized block
    const latestBlock = await connection.getLatestBlockhash('finalized');
    const tx = new Transaction().add(
      createTransferCheckedInstruction(
        fromAccount.address, uselessToken, toAccount.address, mySOLWallet, amount, decimals, undefined, TOKEN_PROGRAM_ID
      )
    )
    tx.recentBlockhash = latestBlock.blockhash
    tx.lastValidBlockHeight = latestBlock.lastValidBlockHeight

    // broadcast the transaction
    const txHash = await sendAndConfirmTransaction(connection, tx, [signer])
    // log transaction hash
    console.log(txHash)
    return txHash;
  } catch (e) {
    // log error
    console.log('error occurred here', e)
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My script can now send "USELESS" token to any valid solana address but I wanted it to send whenever I receive a similar amount on BSC. And to achieve this, it will lead us to...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create USELESS (BSC) token and deploy it on Binance Smart Chain network.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1x2g2338q6un9lcne8na.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1x2g2338q6un9lcne8na.png" alt="Useless Token on BSC" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you see in the image above, I have imported the ERC20 libraries I wanted. (ERC20Permit is optional but recommended) then deployed it on the network at &lt;a href="https://bscscan.com/token/0x84109ff145df1f2f3df12ad57bc104d96e034f58"&gt;0x84109ff145Df1F2f3df12AD57BC104d96E034f58&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But this is not enough as I need the users to submit their solana address whenever they are making a deposit so that my bridge script can pick it up automatically and send then the equivalent spl-token. I deployed the contract for this successfully at &lt;a href="https://bscscan.com/address/0x3B156913F104287eb1cA166C3cf5F8F0f59e561E#code"&gt;UselessPurseBSC&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9qd44x4gkewez6pcsfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx9qd44x4gkewez6pcsfr.png" alt="UselessPurseBSC" width="800" height="764"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then I modified my "useless.ts" script accordingly by including the new lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// useless.ts
...
import { Contract, JsonRpcProvider } from 'ethers'
const uselessPurseABI = [   {
  "anonymous": false,
  "inputs": [
    {
      "indexed": false,
      "internalType": "address",
      "name": "bscSender",
      "type": "address"
    },
    {
      "indexed": false,
      "internalType": "uint256",
      "name": "amount",
      "type": "uint256"
    },
    {
      "indexed": false,
      "internalType": "string",
      "name": "solReceiver",
      "type": "string"
    }
  ],
  "name": "Deposit",
  "type": "event"
}]
const uselessTokenPurseBSC = '0x3B156913F104287eb1cA166C3cf5F8F0f59e561E'
const bscConnection = new JsonRpcProvider('https://go.getblock.io/&amp;lt;api-key&amp;gt;')
const uselessPurse = new Contract(uselessTokenPurseBSC, uselessPurseABI, bscConnection)
...

// this will watch for the deposit event on our UselessPurse contract 
// this is the entry point to the bridge
uselessPurse.on('Deposit', async(_: string, amount: string, receiver: string) =&amp;gt;  {
  // a good idea would be to queue responses first or store them in a database and then fulfill them automatically at intervals later on
  // because of many potential problems including as rate-limiting on the node, invalid solana address,
// exhausted funds for solana token transfer, 
// any other unforeseen technical error

  // fulfill the token transfer
  await sendSolanaToken(receiver, Number(amount))
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the above done, I could now run my bridge script using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bun --watch useless.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using a client side dApp or bscscan explorer, users can deposit tokens into the UselessPurse contract and they will get the equivalent in their provided solana wallet.&lt;/p&gt;

&lt;p&gt;Conclusion:&lt;br&gt;
The use of crypto bridge is important because of the consistent evolution of blockchain technology and the need for projects and startups to make their utility tokens interoperable with multiple chains. In this article, we built a simple unilateral bridge that accepts tokens deposits on BSC network and automatically transfer equivalent amount on solana network. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IMPORTANT&lt;/strong&gt; None of the contracts in this tutorial has been audited and therefore cannot be guaranteed to be safe to use but serve well as good reference for educational material.  &lt;/p&gt;

&lt;p&gt;Further reading:&lt;br&gt;
&lt;a href="https://www.cryptovantage.com/guides/a-guide-to-cryptocurrency-bridges-and-how-they-work"&gt;A crash course in crypto currency bridges&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wormhole.com/blog/"&gt;Wormhole Blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://solana.com/docs/clients/javascript"&gt;Solana Clients&lt;/a&gt;&lt;br&gt;
&lt;a href="https://spl.solana.com/"&gt;SPL Token&lt;/a&gt;&lt;br&gt;
&lt;a href="https://metaboss.rs/overview.html"&gt;Metaboss&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Node (Affiliate Link)&lt;br&gt;
&lt;a href="https://account.getblock.io/sign-in?ref=MTE5MDQ2YWQtM2JmNi01N2FlLWE1ZmYtYjhjNWZiM2ExZ"&gt;Getblock&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Repo:&lt;br&gt;
&lt;a href="https://github.com/rexdavinci/useless-cross-chain-token"&gt;cross chain token repo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Compile Solidity In The Browser</title>
      <dc:creator>Abdulhafiz</dc:creator>
      <pubDate>Mon, 03 Oct 2022 15:40:21 +0000</pubDate>
      <link>https://dev.to/abdhafizahmed/compile-solidity-in-the-browser-16d9</link>
      <guid>https://dev.to/abdhafizahmed/compile-solidity-in-the-browser-16d9</guid>
      <description>&lt;p&gt;Like me, if you have run into issues using Browser-solc when trying to create an app that could compile solidity in the client using ReactJS, this article is for you. We'll see how to use of &lt;code&gt;@agnostico/browser-solidity-compiler&lt;/code&gt; to acheive our result shortly, getting rid of common issues you are likely to face.&lt;/p&gt;

&lt;p&gt;There are many reasons why you may want to compile a solidity smart contract in the browser; Maybe you are building the next &lt;a href="https://remix.ethereum.org" rel="noopener noreferrer"&gt;remix&lt;/a&gt; or you are building an entirely different application and you simply want to have the client fully take control of what is compiled as with the case with what I am building, &lt;a href="https://agnostico.xyz" rel="noopener noreferrer"&gt;Agnostico&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Since the &lt;code&gt;eth_compile&lt;/code&gt; API was &lt;a href="https://github.com/ethereum/EIPs/issues/209" rel="noopener noreferrer"&gt;deprecated&lt;/a&gt;, the available alternatives (&lt;a href="https://github.com/ethereum/solc-js" rel="noopener noreferrer"&gt;Solc-JS&lt;/a&gt; and the extended &lt;a href="https://github.com/ericxtang/browser-solc" rel="noopener noreferrer"&gt;Browser-Solc&lt;/a&gt;) work best in a server setup or is tightly coupled to the HTML DOM, they are not so flexible to work with in modern Javascript library environment such as ReactJS, well at least, not so straight-forward. This will make your application throw tantrums as you develop with them which, from my experience, is a terrible developer experience.&lt;/p&gt;

&lt;p&gt;To allow others build their applications with ease, I built on the provisions of solcjs and created a package that can work efficiently in such development environments (and with typescript support). It uses &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API" rel="noopener noreferrer"&gt;webworkers&lt;/a&gt; under the hood to offload heavy compilation computations from our main thread. Let's take a look at it in action.&lt;/p&gt;

&lt;p&gt;The project is available in the &lt;a href="https://github.com/rexdavinci/browser-solidity-compiler/tree/example" rel="noopener noreferrer"&gt;example&lt;/a&gt; branch of the repo. I will explain how it works here with snippets so let's get to it.&lt;/p&gt;

&lt;p&gt;The example repository is built with &lt;a href="https://github.com/facebook/create-react-app#readme" rel="noopener noreferrer"&gt;create-react-app&lt;/a&gt;, and to install our package, we run&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i @agnostico/browser-solidity-compiler&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Using the package in our application,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.tsx
...
import {
  getCompilerVersions,
  solidityCompiler,
} from '@agnostico/browser-solidity-compiler';
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the &lt;code&gt;getCompilerVersions&lt;/code&gt; is an async operation that fetches the list of existing solidity versions from &lt;code&gt;https://binaries.soliditylang.org/bin/list.json&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;// App.tsx
...
const loadVersions = async () =&amp;gt; {
 const { releases, latestRelease, builds } = await getCompilerVersions()
};

// Load versions immediately page is mounted
useEffect(() =&amp;gt; {
 (async () =&amp;gt; { 
   await loadVersions() 
  })();
 }, []);
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our returned object looks like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3nicxqqpgrb676p9n4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3nicxqqpgrb676p9n4n.png" alt="Solidity Versions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then to compile our contracts, we select the  we simply pass the required arguments into the compiler object. Our version will look similar to this if we are not using a template literal: &lt;code&gt;https://binaries.soliditylang.org/bin/soljson-v0.8.17+commit.8df45f5f.js&lt;/code&gt; (If we are using solidity version 0.8.17). But to make it dynamic in cases where the user can switch between versions, we implement like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.tsx
...
const compiled = (await solidityCompiler({ 
version: `https://binaries.soliditylang.org/bin/${usingVersion}`,
 contractBody: content,
 options,
}));
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;contractBody&lt;/code&gt; is the string of the contract(s) to be compiled. while &lt;code&gt;options&lt;/code&gt; the optimization object. It is optional. For example, you could have optimization looking like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;options.optimizer = {
  enabled: true,
  runs: 200,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our contracts in the example repo was returned in the compiled variable, stored in state and accessed this way&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.tsx
Object.keys(compiledContract?.contracts?.Compiled_Contracts).map((cont) =&amp;gt; (
  &amp;lt;div key={cont}&amp;gt;
   &amp;lt;p&amp;gt;{cont}&amp;lt;/p&amp;gt;

  &amp;lt;span&amp;gt;Bytecode&amp;lt;/span&amp;gt;: &amp;lt;small&amp;gt;
{
                      compiledContract?.contracts?.Compiled_Contracts[cont]?.evm?.bytecode?.object
 }
   &amp;lt;/small&amp;gt;
 &amp;lt;/div&amp;gt;
 )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The contract(s) are stored in a property of the returned object called &lt;code&gt;Compiled_Contracts&lt;/code&gt; where we can access their information such as the &lt;code&gt;abi&lt;/code&gt; or &lt;code&gt;bytecode&lt;/code&gt; and shown above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://github.com/ethereum/solc-js" rel="noopener noreferrer"&gt;Solc-JS&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/rexdavinci/browser-solidity-compiler/tree/main" rel="noopener noreferrer"&gt;@agnostico/browser-solidity-compiler&lt;/a&gt;&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>webworker</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Creating an ERC20/BEP20 token without libraries with testing (part 1)</title>
      <dc:creator>Abdulhafiz</dc:creator>
      <pubDate>Wed, 25 May 2022 14:54:26 +0000</pubDate>
      <link>https://dev.to/abdhafizahmed/creating-an-erc20bep20-token-without-libraries-with-testing-part-1-288i</link>
      <guid>https://dev.to/abdhafizahmed/creating-an-erc20bep20-token-without-libraries-with-testing-part-1-288i</guid>
      <description>&lt;p&gt;The aim of this tutorial is to demonstrate the creation of a ERC20-compliant token. The code is not audited and should not be used in production.&lt;/p&gt;

&lt;p&gt;Requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of solidity.&lt;/li&gt;
&lt;li&gt;An internet browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are completely new to solidity, you may wish to check out these resources: &lt;a href="https://ethereum.org/en/developers/"&gt;ethereum.org&lt;/a&gt; or if you prefer videos like me, you can check out &lt;a href="https://www.youtube.com/channel/UCJWh7F3AFyQ_x01VKzr9eyA"&gt;Solidity Programmer&lt;/a&gt; on youtube.&lt;/p&gt;

&lt;p&gt;Let's begin coding, navigate to from your browser to &lt;a href="https://remix.ethereum.org"&gt;https://remix.ethereum.org&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remix IDE allows developing, deploying and administering smart contracts for Ethereum like blockchains.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In remix, we'll create a new file in our workspace, let's call it RawToken.sol &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WdLXq-xI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b99hd5ja522cc87411t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WdLXq-xI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0b99hd5ja522cc87411t.png" alt="Remix IDE" width="880" height="638"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Explanation: &lt;/p&gt;

&lt;p&gt;1- We started by specifying the license and version of solidity we want to write in.&lt;a href="https://docs.soliditylang.org/en/latest/layout-of-source-files.html"&gt;[1]&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;2- We defined the events that will be emitted to the chain when some actions are performed on our token contract.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Approval&lt;/code&gt; - is emitted when an account changes the amount that another account can spend from its balance. e.g when you a smart contract should automatically transfer an amount from your account to itself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Transfer&lt;/code&gt; - is emitted when token transfer is successful.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3- These values are not expected to change throughout the lifetime of our contract. (This requirement is specific to our example contract).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NAME&lt;/code&gt; - token name. In this example, token name is "ERC20 Token".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SYMBOL&lt;/code&gt; - token symbol. In this example, token symbol is "T-O-K-E-N".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_decimals&lt;/code&gt; - token decimals.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_totalSupply&lt;/code&gt;- total supply of token. We won't be minting more tokens after our token is deployed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4- We track some of the variables that relate to transfers and balance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;_balances&lt;/code&gt; - tracks the balance of token(s) owned by an account&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_allowances&lt;/code&gt; - tracks the amount of tokens another account has approved for it to spend on its behalf.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;5- &lt;strong&gt;Constructor&lt;/strong&gt;&lt;br&gt;
During our contract construction, we supplied two arguments and also mint all the tokens we want to the deployer's account.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;supply&lt;/code&gt; - The exact amount of tokens we want to mint. e.g if we want 1,000,000 tokens, we will specify "1000000" &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_decimal&lt;/code&gt; - The decimals we want our token to have. Each token will be calculated using &lt;code&gt;n * 10 ^ _decimal&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;6- A set of functions that return the read-only variables and/or constants. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;totalSupply&lt;/code&gt; - Returns the total supply of the token in existence.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;decimals&lt;/code&gt; - Returns the decimals of the token.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;symbol&lt;/code&gt; - Returns the token symbol.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt; - Returns the token's name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;balanceOf&lt;/code&gt; - Tracks the amount of tokens owned by an account.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;allowance&lt;/code&gt; - Tracks the allowance approved by an account for another account.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;7- A set of functions that mutates the state of our token contract.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;approve&lt;/code&gt; - Used by an account to increase or decrease the &lt;code&gt;amount&lt;/code&gt; of tokens the &lt;code&gt;spender&lt;/code&gt; account can spend on its behalf. Very useful when interacting with dApps.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;transfer&lt;/code&gt; - Lets an account transfer an &lt;code&gt;amount&lt;/code&gt; of tokens from its balance or allowance &lt;code&gt;to&lt;/code&gt; another account.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;transferFrom&lt;/code&gt; - Enables an account make a transfer to a beneficiary from the balance of another account. Relies on the allowance provided by the &lt;code&gt;from&lt;/code&gt; account.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;_transferFrom&lt;/code&gt; - Handles the transfer logic while updating the balances of the sender and receiver.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Deployment&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DQR6IGc9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pshvsvxec8k70clxz0rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DQR6IGc9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pshvsvxec8k70clxz0rb.png" alt="Deployment View" width="716" height="1154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1- The token is being deployed in the local virtual environment provided by remix IDE.&lt;br&gt;
2- An account also provided by remix starts with &lt;code&gt;0x5B3&lt;/code&gt; and ends with &lt;code&gt;eddC4&lt;/code&gt; will be used to deploy the contract.&lt;br&gt;
3- The constructor arguments are provided during contract construction. Here, we are minting exactly 5 million tokens and we have requested that the contract uses 9 decimals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_8axgWAZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpplpodwnfvbyq0roilf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_8axgWAZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xpplpodwnfvbyq0roilf.png" alt="Functions Call" width="598" height="1788"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4- &lt;code&gt;balanceOf&lt;/code&gt; function returns the balance of the deployer which in our case, is the total supply of the token since we "minted" this amount to the deployer inside the contract's constructor.&lt;br&gt;
5- &lt;code&gt;decimals&lt;/code&gt; returns correct value of 9.&lt;br&gt;
6- &lt;code&gt;name&lt;/code&gt; returns correct value &lt;code&gt;ERC20 Token&lt;/code&gt;.&lt;br&gt;
7- &lt;code&gt;symbol&lt;/code&gt; returns the correct value of "T-O-K-E-N".&lt;br&gt;
8- &lt;code&gt;totalSupply&lt;/code&gt; returns the total supply of the tokens which is equal to the amount minted to the deployer explained earlier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
This tutorial demonstrates how to create an ERC20-compliant token. This is not advised to be used in production as existing implementation such as &lt;a href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"&gt;openzeppelin&lt;/a&gt; is battle-tested and audited by various projects.&lt;/p&gt;

&lt;p&gt;In the subsequent article to this, I will be moving the code to VSCode and use &lt;a href="https://hardhat.org"&gt;hardhat&lt;/a&gt; environment to compile, test and deploy &lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.soliditylang.org/en/latest/layout-of-source-files.html"&gt;Solidity Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://remix-project.org/"&gt;Remix Project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.openzeppelin.com"&gt;Openzeppelin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>solidity</category>
      <category>tutorial</category>
      <category>web3</category>
      <category>hardhat</category>
    </item>
  </channel>
</rss>
