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

automatic gas estimation #855

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/seth/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 eth `ETH_GAS` is not set

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions src/seth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ 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
seth-send: warning: `ETH_GAS' not set; using estimated gas amount
Ethereum account passphrase (not echoed):
seth-send: Published transaction with 0 bytes of calldata.
seth-send: 0xe428d4bb148ded426777ae892578507e4f394f608ad9d3a9d0229e8348ba72e3
Expand Down Expand Up @@ -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 |
Expand Down
22 changes: 19 additions & 3 deletions src/seth/libexec/seth/seth-mktx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,36 @@ if [[ $2 ]]; then
data=$(seth calldata "${@:2}")
fi

data=${data:-0x}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we put this in an else for the above if statement?


if [[ -z "$SETH_CREATE" ]]; then
TO=$(seth --to-address "$1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only for --create?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If SETH_CREATE is unset, then we are doing a normal transaction that has a recipient. If not, we are creating a contract, and TO must be unset since this is a requirement for a contract creation tx.

fi

if [[ -z "$ETH_GAS" ]]; then
jshon+=(-n {})
[[ $TO ]] && jshon+=(-s "$TO" -i to)
jshon+=(-s "$data" -i data)
# shellcheck disable=SC2207
jshon+=($(SETH_PARAMS_NO_GAS=1 seth --send-params))
jshon+=(-i append)
ETH_GAS=$(seth rpc eth_estimateGas -- "${jshon[@]}")
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
Expand Down
2 changes: 1 addition & 1 deletion src/seth/libexec/seth/seth-send
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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"
echo >&2 "${0##*/}: warning: \`ETH_GAS' not set; using estimated gas amount"
ncitron marked this conversation as resolved.
Show resolved Hide resolved
if [[ $SETH_RESEND ]]; then
nonce=$(seth nonce "$ETH_FROM")
export ETH_NONCE=$nonce
Expand Down