exec
Call a contract function, encoding the arguments from its signature.
Syntax
Section titled “Syntax”exec <contractAddress> <signature> [...params]Arguments
Section titled “Arguments”| Name | Type | Description |
|---|---|---|
contractAddress |
address |
Target contract address |
signature |
write-abi |
Function signature (e.g. "transfer(address,uint256)") |
[...params] |
any |
Arguments matching the signature types |
Options
Section titled “Options”| Name | Type | Description |
|---|---|---|
--value |
number |
ETH to send with the call (in wei) |
--from |
address |
Sender address (requires simulation or connected wallet) |
--gas |
number |
Gas limit |
--max-fee-per-gas |
number |
Max fee per gas (EIP-1559) |
--max-priority-fee-per-gas |
number |
Max priority fee per gas (EIP-1559) |
--nonce |
number |
Transaction nonce override |
Examples
Section titled “Examples”# Approve a tokenexec @token(DAI) "approve(address,uint256)" 0x64c007ba4ab6184753dc1e8e7263e8d06831c5f6 1200e18
# Send ETH with the callexec 0xe91d153e0b41518a2ce8dd3d7944fa863463a97d "deposit()" --value 1e18
# Specify senderexec @token(DAI) "approve(address,uint256)" 0x64c007ba4ab6184753dc1e8e7263e8d06831c5f6 1200e18 --from 0x44fA8E6f47987339850636F88629646662444217
# Capture events from the transactionload simset $wxdai 0xe91d153e0b41518a2ce8dd3d7944fa863463a97dsim:fork --using anvil ( sim:set-balance @me 1e18 exec $wxdai "deposit()" --value 0.001e18 -> Deposit(address indexed, uint) [_ $amount] exec $wxdai "withdraw(uint)" $amount)
# Complex parameter typesexec 0xd0e81E3EE863318D0121501ff48C6C3e3Fd6cbc7 "addBatches(bytes32[],bytes)" [0x02732126661d25c59fd1cc2308ac883b422597fc3103f285f382c95d51cbe667] @bytes(QmTik4Zd7T5ALWv5tdMG8m2cLiHmqtTor5QmnCSGLUjLU2)Error Captures
Section titled “Error Captures”Error captures (-!> / -?!>) catch transaction reverts and decode the error data into variables. Three forms are available after the error name: nothing (assertion only), destructure ([...]), or a boolean variable ($var).
set $c 0x44fA8E6f47987339850636F88629646662444217
# Assert a specific error without capturing dataexec $c "deny()" -!> Unauthorized()
# Destructure error arguments into variablesexec $c "withdraw(uint256)" 200 -!> InsufficientBalance(uint256,uint256) [$balance $required]
# Catch a require/revert reasonexec $c "transfer(address,uint256)" @me 100e18 -!> Error(string) [$reason]
# Boolean variable: $e is "true" if the error matchedexec $c "deny()" -!> Unauthorized() $e
# Generic catch-all (no error name)exec $c "doSomething()" -!> [$reason]exec $c "doSomething()" -!> $e
# Optional: skip silently if tx succeedsexec $c "maybeRevert()" -?!> Error(string) [$reason]exec $c "maybeRevert()" -?!> Unauthorized() $e # $e = "false" if tx succeeds or wrong error-!>expects the transaction to revert; throws if it succeeds-?!>captures the error if the tx reverts; silently continues if it succeeds- With a boolean variable (
$e),-?!>sets$e = "false"on success or mismatched error;-!>always sets$e = "true"(throws otherwise) - Supported error types: custom named errors,
Error(string)(require/revert),Panic(uint256)(assert), and empty reverts
- The signature follows Solidity syntax:
"functionName(type1,type2)" - Parameters are automatically ABI-encoded based on the signature
- Use
--valueto send ETH with the call - Use
--fromto impersonate a sender (requires simulation mode) - Event captures (
->) execute the transaction immediately and store decoded log values in variables - Error captures (
-!>/-?!>) catch and decode transaction reverts