diff --git a/src/seth/CHANGELOG.md b/src/seth/CHANGELOG.md
index 4b2ea6403..24aaa460a 100644
--- a/src/seth/CHANGELOG.md
+++ b/src/seth/CHANGELOG.md
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `seth index` command returns the slot number for the specified mapping type and input data
- `seth --from-fix` command converts fixed point numbers into parsed integers with the specified number of decimals
- `seth run-tx` now fetches contract source from etherscan if `ETHERSCAN_API_KEY` is set
+- `seth mktx` now estimates gas limit if `ETH_GAS` is not set
+- `seth send` now estimates gas limit if `ETH_GAS` is not set
### Fixed
diff --git a/src/seth/README.md b/src/seth/README.md
index 2e52b1202..0786eae9c 100644
--- a/src/seth/README.md
+++ b/src/seth/README.md
@@ -238,7 +238,6 @@ wei—the smallest possible amount of ether—to the [Ethereum
Foundation's donation address]:
$ seth send --value 1 0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359
- seth-send: warning: `ETH_GAS' not set; using default gas amount
Ethereum account passphrase (not echoed):
seth-send: Published transaction with 0 bytes of calldata.
seth-send: 0xe428d4bb148ded426777ae892578507e4f394f608ad9d3a9d0229e8348ba72e3
@@ -660,6 +659,7 @@ node's gas estimation.
seth estimate [] []
seth estimate [] --create []
seth estimate [] --create
+ seth estimate [] --create
Options are similar to [`seth send`], but no transaction is published.
@@ -829,7 +829,7 @@ Sign and publish a transaction to the blockchain.
| ------------- | --------------- | ------------ | --------------- |
| `--block` | `ETH_BLOCK` | `latest` | block number |
| `--from` | `ETH_FROM` | n/a | sender |
-| `--gas` | `ETH_GAS` | `200000` | gas quantity |
+| `--gas` | `ETH_GAS` | estimated | gas quantity |
| `--gas-price` | `ETH_GAS_PRICE` | | gas price |
| `--prio-fee` | `ETH_PRIO_FEE` | | EIP-1559 priority fee (miner tip) |
| `--value` | `ETH_VALUE` | `0` | ether value |
diff --git a/src/seth/libexec/seth/seth-estimate b/src/seth/libexec/seth/seth-estimate
index 41864607e..26e03fd5e 100755
--- a/src/seth/libexec/seth/seth-estimate
+++ b/src/seth/libexec/seth/seth-estimate
@@ -4,6 +4,7 @@
### or: seth estimate []
### or: seth estimate [] --create []
### or: seth estimate [] --create
+### or: seth estimate [] --create
###
### Perform a local call to and return the gas usage.
###
@@ -15,7 +16,7 @@
### With `-F ', simulate calling from
### With `-V ', simulate transferring to .
set -e
-[[ $2 ]] || seth --fail-usage "$0"
+[[ $1 ]] || seth --fail-usage "$0"
if [[ $SETH_CREATE ]]; then
DATA=$(seth --to-hexdata "$1")
diff --git a/src/seth/libexec/seth/seth-mktx b/src/seth/libexec/seth/seth-mktx
index d5790b27e..b9a340fdd 100755
--- a/src/seth/libexec/seth/seth-mktx
+++ b/src/seth/libexec/seth/seth-mktx
@@ -13,20 +13,34 @@ if [[ $2 ]]; then
data=$(seth calldata "${@:2}")
fi
+data=${data:-0x}
+
+if [[ -z "$SETH_CREATE" ]]; then
+ TO=$(seth --to-address "$1")
+fi
+
+if [[ -z "$ETH_GAS" ]]; then
+ if [[ $SETH_CREATE ]]; then
+ ETH_GAS=$(seth estimate --create $data)
+ else
+ ETH_GAS=$(seth estimate $TO $data)
+ fi
+fi
+
args=(
--from "$(seth --to-address "$ETH_FROM")"
--nonce "${ETH_NONCE:-$(seth nonce "$ETH_FROM")}"
--chain-id "$(seth chain-id)"
--gas-price "${ETH_GAS_PRICE:-$(seth gas-price)}"
- --gas-limit "${ETH_GAS:-200000}"
+ --gas-limit "$ETH_GAS"
--value "$value"
- --data "${data:-0x}"
+ --data "$data"
)
if [[ $SETH_CREATE ]]; then
args+=(--create)
else
- args+=(--to "$(seth --to-address "$1")")
+ args+=(--to "$TO")
fi
if [[ $ETH_PRIO_FEE ]]; then
diff --git a/src/seth/libexec/seth/seth-send b/src/seth/libexec/seth/seth-send
index f12300de7..3d72f1b5d 100755
--- a/src/seth/libexec/seth/seth-send
+++ b/src/seth/libexec/seth/seth-send
@@ -23,8 +23,6 @@ set -e
[[ $ETH_FROM ]] ||
seth --fail "${0##*/}: error: \`ETH_FROM' not set; send from which account?"
-[[ $ETH_GAS ]] ||
-echo >&2 "${0##*/}: warning: \`ETH_GAS' not set; using default gas amount"
if [[ $SETH_RESEND ]]; then
nonce=$(seth nonce "$ETH_FROM")
export ETH_NONCE=$nonce
@@ -44,9 +42,18 @@ else
fi
fi
+if [[ -z "$ETH_GAS" ]]; then
+ if [[ $SETH_CREATE ]]; then
+ ETH_GAS=$(seth estimate --create $DATA)
+ else
+ ETH_GAS=$(seth estimate $TO ${DATA:-0x})
+ fi
+fi
+
jshon+=(-n {})
[[ $TO ]] && jshon+=(-s "$TO" -i to)
[[ $DATA ]] && jshon+=(-s "$DATA" -i data)
+[[ $ETH_GAS ]] && jshon+=(-s "$ETH_GAS" -i gas)
# shellcheck disable=SC2207
jshon+=($(seth --send-params))
jshon+=(-i append)