<?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>Developers Forum for XinFin XDC Network: SilentZero</title>
    <description>The latest articles on Developers Forum for XinFin XDC Network by SilentZero (@silentzero).</description>
    <link>https://www.xdc.dev/silentzero</link>
    <image>
      <url>https://www.xdc.dev/images/0Inm9AExk69QbHPDG3tGxNxyyBg2ibqUwg0T9-tsex8/rs:fill:90:90/mb:500000/ar:1/aHR0cHM6Ly93d3cu/eGRjLmRldi91cGxv/YWRzL3VzZXIvcHJv/ZmlsZV9pbWFnZS81/NDY1L2M1OTMyODhj/LTY2ZDctNDI0My05/NDFjLTc0MWM0ZDUw/NWFkZi5wbmc</url>
      <title>Developers Forum for XinFin XDC Network: SilentZero</title>
      <link>https://www.xdc.dev/silentzero</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://www.xdc.dev/feed/silentzero"/>
    <language>en</language>
    <item>
      <title>How to call totalSupply and balanceOf of an XRC-20 (ERC-20) token on XDC/Ethereum using Rust + Alloy.rs?</title>
      <dc:creator>SilentZero</dc:creator>
      <pubDate>Sun, 29 Jun 2025 07:58:23 +0000</pubDate>
      <link>https://www.xdc.dev/silentzero/how-to-call-totalsupply-and-balanceof-of-an-xrc-20-erc-20-token-on-xdcethereum-using-rust-alloyrs-4k81</link>
      <guid>https://www.xdc.dev/silentzero/how-to-call-totalsupply-and-balanceof-of-an-xrc-20-erc-20-token-on-xdcethereum-using-rust-alloyrs-4k81</guid>
      <description>&lt;p&gt;I'm trying to interact with a deployed &lt;strong&gt;XRC-20 token contract&lt;/strong&gt; on the &lt;strong&gt;XDC Network (EVM-compatible)&lt;/strong&gt; using &lt;strong&gt;Rust&lt;/strong&gt; and the &lt;a href="https://alloy.rs/"&gt;&lt;code&gt;alloy&lt;/code&gt;&lt;/a&gt; crate.&lt;/p&gt;

&lt;p&gt;I have already deployed my token using &lt;strong&gt;MetaMask&lt;/strong&gt; and Remix IDE, and I can see it on the XDC Apothem explorer.&lt;/p&gt;

&lt;p&gt;Now I want to use &lt;code&gt;alloy&lt;/code&gt; in Rust to &lt;strong&gt;read the &lt;code&gt;totalSupply&lt;/code&gt; and &lt;code&gt;balanceOf&lt;/code&gt;&lt;/strong&gt; of that token.&lt;/p&gt;

&lt;p&gt;I'm trying this basic setup using the &lt;code&gt;sol!&lt;/code&gt; macro:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;sol!&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;interface&lt;/span&gt; &lt;span class="n"&gt;IERC20&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;totalSupply&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;external&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="nf"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;external&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="nf"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uint256&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But I’m not sure what the &lt;strong&gt;minimal working code&lt;/strong&gt; looks like to connect to XDC RPC &lt;a href="https://rpc.apothem.network"&gt;https://rpc.apothem.network&lt;/a&gt; by using a &lt;strong&gt;PrivateKeySigner&lt;/strong&gt; from MetaMask to call &lt;code&gt;totalSupply()&lt;/code&gt; and &lt;code&gt;balanceOf(my_addr)&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;I tried to take help from &lt;a href="https://alloy.rs/examples/wallets/README"&gt;https://alloy.rs/examples/wallets/README&lt;/a&gt; but could not find something easy to usable.&lt;/p&gt;

&lt;p&gt;I already have my token contract address, MetaMask wallet private key and RPC address.&lt;/p&gt;

&lt;p&gt;So I am needing a &lt;strong&gt;minimal working example&lt;/strong&gt; in Rust using &lt;code&gt;alloy&lt;/code&gt; that can loads a private key and Connects to an RPC and call &lt;code&gt;IERC20::totalSupply()&lt;/code&gt; and &lt;code&gt;IERC20::balanceOf()&lt;/code&gt; on the deployed contract&lt;/p&gt;

</description>
      <category>rust</category>
      <category>alloy</category>
      <category>metamask</category>
      <category>solidity</category>
    </item>
  </channel>
</rss>
