foundry
foundry copied to clipboard
feat(cast): remove redundant `cast` commands
Component
Cast
Describe the feature you would like
Currently, to-dec and to-hex act as specialized versions of to-base making them both redundant.
These should probably be deprecated to remove clutter and simplify the tool and leave to-base as a catch-all for converting from one radix to another.
Additional context
I can think of other such simplifications that can be made to some of these conversion commands, but I'll stick with just this one for now and add others in the event we decide to move forward with this.
I do agree with you that cast has a good amount of clutter in the commands and could benefit from a refactor.
Before deprecating the mentioned commands, I think it'd be ideal to instead survey all cast commands think about how they should be cleaned up and deduped more broadly. For example, it is convenient to have an alias since converting between decimal and hex is common, so a better approach might be to have subcommands. For example:
# Top level command that doesn't actually do anything
cast convert
# Subcommands to convert to the respective types
cast convert to-dec
cast convert to-hex
cast convert to-base 2 # convert to binary
# And they each take a flag to specify padding
cast convert to-dec --pad 32 # pad to 32 bytes, e.g. uint256
cast convert to-hex --pad 32 # pad to 32 bytes, e.g. bytes32
# Maybe we have aliases for common pad amounts
cast convert to-uint256 # equivalent to `cast convert to-dec --pad 32
cast convert to-address # equivalent to `cast convert to-hex --pad 20
There's a bunch of other existing related conversion commands that might fit in here, e.g. to-int256, etc.
And I'm saying the above proposal is optimal just yet, so open to other ideas
Yep I agree we could probably refactor cast a bit—we have to be careful about breaking changes around this though
We can rework this to be a meta issue on cast refactoring if you guys would like.
Supportive of making this a meta issue, and agreed around being careful about breaking changes
Sharing a potential starting point for a refactor, largely courtesy of Claude. Very likely some commands are missing, and cast convert still needs fleshing out as mentioned above
cast <COMMAND>
Commands:
ens
resolve-name Perform an ENS lookup
lookup-address Perform an ENS reverse lookup
namehash Calculate the ENS namehash of a name
tx
build Build a transaction (formerly mktx)
send Sign and publish a transaction
receipt Get the transaction receipt for a transaction
get Get information about a transaction (formerly tx)
decode Decode a raw signed EIP 2718 typed transaction (formerly decode-transaction)
block
get Get information about a block (formerly block)
number Get the latest block number (formerly block-number)
basefee Get the basefee of a block (formerly base-fee)
timestamp Get the timestamp of a block
find Get the block number closest to the provided timestamp (formerly find-block)
account
balance Get the balance of an account in wei
nonce Get the nonce for an account
code Get the runtime bytecode of a contract
storage Get the raw value of a contract's storage slot
proof Generate a storage proof for a given storage slot
compute-address Compute the contract address from a given nonce and deployer address
implementation Fetch the EIP-1967 implementation account
admin Fetch the EIP-1967 admin account
abi
encode ABI encode the given function arguments (formerly abi-encode)
decode Decode ABI-encoded input or output data (formerly abi-decode)
calldata ABI-encode a function with arguments
calldata-decode Decode ABI-encoded input data (formerly calldata-decode)
event Get the event signature for a given topic 0 (formerly 4byte-event)
signature Get the function signatures for the given selector (formerly 4byte)
convert (migrates original commands, suggestions for new ones in https://github.com/foundry-rs/foundry/issues/5467#issuecomment-1652068862)
to-wei Convert an ETH amount to wei
from-wei Convert wei into an ETH amount
to-hex Convert a number to hexadecimal
from-hex Convert a hexadecimal number to decimal
to-uint256 Convert a number to a hex-encoded uint256
to-int256 Convert a number to a hex-encoded int256
from-utf8 Convert UTF8 text to hex (formerly from-utf8)
to-ascii Convert hex data to an ASCII string
to-rlp RLP encode hex data or an array of hex data
from-rlp Decode RLP encoded data
concat-hex Concatenate hex strings
to-checksum Convert an address to a checksummed format (EIP-55) (formerly to-checksum-address)
to-fixed-point Convert an integer into a fixed point number
from-fixed-point Convert a fixed point number into an integer
util
keccak Hash arbitrary data using Keccak-256
selectors Extract function selectors and arguments from bytecode
disassemble Disassemble hex encoded bytecode into human readable opcodes
selector Get the selector for a function (formerly sig)
index Compute the storage slot for an entry in a mapping
generate
interface Generate a Solidity interface from a given ABI
event-signature Generate event signatures from event string (formerly sig-event)
fig-spec Generate Fig autocompletion spec
shell-completion Generate shell completions script
rpc
send Perform a raw JSON-RPC request (formerly rpc)
client-version Get the current client version
chain-id Get the Ethereum chain ID
gas-price Get the current gas price
logs Get logs by signature or topic
call Perform a call on an account without publishing a transaction
estimate Estimate the gas cost of a transaction
access-list Create an access list for a transaction
cc https://github.com/foundry-rs/foundry/issues/7611