Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cast): support short cut for querying erc20 balance in cast balance #6828

Merged
merged 6 commits into from
Jan 26, 2024
Merged

feat(cast): support short cut for querying erc20 balance in cast balance #6828

merged 6 commits into from
Jan 26, 2024

Conversation

fenghaojiang
Copy link
Contributor

@fenghaojiang fenghaojiang commented Jan 17, 2024

Motivation

Closes #6813

As erc20 / erc721 standards become common sense, I want to make a short cut to query erc20 / erc721 balance without having to write following script:

cast call [token_address] "balanceOf(address) returns uint256" --rpc-url=https://rpc.ankr.com/eth 

After this PR:
querying erc20 balance would be easier. like:

cast balance 0x162c6270266667ccf5a9ed752b5d6a2bdc0f90de --token=0x5a98fcbea516cf06857215779fd812ca3bef1b32  --rpc-url=https://rpc.ankr.com/eth

And support ENS:

cast balance vitalik.eth --token=0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b  --rpc-url=https://rpc.ankr.com/eth

The original cast balance remains unchanged.

cast balance birdring.eth  --rpc-url=https://rpc.ankr.com/eth

After new option --token added into cast balance --help:

Get the balance of an account in wei

Usage: cast balance [OPTIONS] <WHO>

Arguments:
  <WHO>
          The account to query

Options:
  -B, --block <BLOCK>
          The block height to query at.

          Can also be the tags earliest, finalized, safe, latest, or pending.

  -e, --ether
          Format the balance in ether

  -r, --rpc-url <URL>
          The RPC endpoint

          [env: ETH_RPC_URL=]

      --flashbots
          Use the Flashbots RPC URL (https://rpc.flashbots.net)

      --jwt-secret <JWT_SECRET>
          JWT Secret for the RPC endpoint.

          The JWT secret will be used to create a JWT for a RPC. For example, the following can be used to simulate a CL `engine_forkchoiceUpdated` call:

          cast rpc --jwt-secret <JWT_SECRET> engine_forkchoiceUpdatedV2 '["0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc",
          "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc", "0x6bb38c26db65749ab6e472080a3d20a2f35776494e72016d1e339593f21c59bc"]'

          [env: ETH_RPC_JWT_SECRET=]

  -t, --token <TOKEN>
          Token address to query, with the method `balanceOf(address) return (uint256)`

  -h, --help
          Print help (see a summary with '-h')

Solution

The solution is in the branch if --token option is not empty and the original cast balance remains unchanged.

crates/cast/bin/main.rs Outdated Show resolved Hide resolved
crates/cast/bin/opts.rs Outdated Show resolved Hide resolved
crates/cast/bin/opts.rs Outdated Show resolved Hide resolved
@fenghaojiang
Copy link
Contributor Author

Problems resolved as you requested. Plz review the code again.

Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Thanks!

@DaniPopes DaniPopes merged commit ee362bd into foundry-rs:master Jan 26, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: add --token option to cast balance
2 participants