Skip to content

Conversation

@marcvernet31
Copy link
Contributor

@marcvernet31 marcvernet31 commented Oct 23, 2025

Motivation

Refactor usage of --erc20 flag into command cast erc20. Onboard additional actions as defined here: #12095

Solution

Introduce a dedicated cast erc20 command with various subcommands for common ERC20 operations:

  • cast erc20 balance <TOKEN> <ACCOUNT> - Query ERC20 token balance (replaces cast balance --erc20)
  • cast erc20 transfer <TOKEN> <TO> <AMOUNT> - Transfer tokens using transfer(address,uint256)
  • cast erc20 approve <TOKEN> <SPENDER> <AMOUNT> - Approve token spending using
    approve(address,uint256)
  • cast erc20 allowance <TOKEN> <OWNER> <SPENDER> - Query allowance using
    allowance(address,address)

Also added a deprecation warning on the --erc20 command.

Tested with a local Anvil node.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcvernet31 thank you! since you mentioned you tested with an anvil node, we could add same in unit tests, here's an example of a cast test that starts anvil and then send cast mktx commands, could you replicate your tests this way?

casttest!(mktx_raw_unsigned_no_from_missing_chain, async |_prj, cmd| {
// As chain is not provided, a query is made to the provider to get the chain id, before the tx
// is built. Anvil is configured to use chain id 1 so that the produced tx will be the same
// as in the `mktx_raw_unsigned` test.
let (_, handle) = anvil::spawn(NodeConfig::test().with_chain_id(Some(1u64))).await;
cmd.args([
"mktx",
"--nonce",
"0",
"--gas-limit",
"21000",
"--gas-price",
"10000000000",
"--priority-gas-price",
"1000000000",
"0x0000000000000000000000000000000000000001",
"--raw-unsigned",
"--rpc-url",
&handle.http_endpoint(),
])
.assert_success()
.stdout_eq(str![[
r#"0x02e80180843b9aca008502540be4008252089400000000000000000000000000000000000000018080c0
"#
]]);
});

@grandizzy grandizzy self-requested a review October 27, 2025 05:56
Copy link
Contributor

@0xrusowsky 0xrusowsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job!
left some minor nits

impl Erc20Subcommand {
pub async fn run(self) -> eyre::Result<()> {
match self {
// TODO: change account for who???
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rmv the todo.
you can add an alias for who instead if u want.

Some(token) => {
let balance =
Cast::new(&provider).erc20_balance(token, account_addr, block).await?;
sh_warn!("--erc20 flag is deprecated, use cast erc20 balance instead")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sh_warn!("--erc20 flag is deprecated, use cast erc20 balance instead")?;
sh_warn!("--erc20 flag is deprecated, use `cast erc20 balance` instead")?;

Comment on lines +29 to +31
/// The account to query.
#[arg(value_parser = NameOrAddress::from_str)]
account: NameOrAddress,
Copy link
Contributor

@0xrusowsky 0xrusowsky Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename it to owner to stick to the ERC20 interface? account was previously used cause --erc20 was just a flag on top of the cmd that would get teh eth balance of an account.

Comment on lines +18 to +19
/// ERC20 token subcommands.
/// CLI arguments for `cast tx-pool`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shows up in the help output, so please fix this up

Suggested change
/// ERC20 token subcommands.
/// CLI arguments for `cast tx-pool`.
/// Interact with ERC20 tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants