I'm trying to interact with a deployed XRC-20 token contract on the XDC Network (EVM-compatible) using Rust and the alloy
crate.
I have already deployed my token using MetaMask and Remix IDE, and I can see it on the XDC Apothem explorer.
Now I want to use alloy
in Rust to read the totalSupply
and balanceOf
of that token.
I'm trying this basic setup using the sol!
macro:
sol! {
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
}
}
But Iām not sure what the minimal working code looks like to connect to XDC RPC https://rpc.apothem.network by using a PrivateKeySigner from MetaMask to call totalSupply()
and balanceOf(my_addr)
I tried to take help from https://alloy.rs/examples/wallets/README but could not find something easy to usable.
I already have my token contract address, MetaMask wallet private key and RPC address.
So I am needing a minimal working example in Rust using alloy
that can loads a private key and Connects to an RPC and call IERC20::totalSupply()
and IERC20::balanceOf()
on the deployed contract
Discussion (4)
Here is the demo for you:
github.com/gzliudan/alloy-demo
I will try to write an demo for you
Please wait. Someone will respond to your query soon.