latticexyz / mud

MUD is a framework for building autonomous worlds
https://mud.dev
MIT License
757 stars 188 forks source link

deployer should check balance and give nicer error #1955

Open holic opened 1 year ago

holic commented 1 year ago

Had a few questions lately about errors related to not enough balance to cover gas of deploy, but the error message from viem isn't very descriptive (gas required exceeds allowance).

We can detect this in the deployer and print out a nicer error message.

holic commented 2 months ago

currently if you deploy from an account with not enough balance, you get an obscure error

ContractFunctionExecutionError: Execution reverted for an unknown reason.

Request Arguments:
  from:                  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
  to:                    0x573802f86c51B61d7Cf620952217eC6Ce0537d2E
  data:                  0x0d84a1b600000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020e25e4fa1caab882c16d559523d1b1bdd471471538be9fc444626b963f032a877
  maxFeePerGas:          0.00010006 gwei
  maxPriorityFeePerGas:  0.0001 gwei
  nonce:                 1594

Contract Call:
  address:   0x573802f86c51B61d7Cf620952217eC6Ce0537d2E
  function:  deployWorld(bytes salt)
  args:                 (0xe25e4fa1caab882c16d559523d1b1bdd471471538be9fc444626b963f032a877)
  sender:    0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

or sometimes

TransactionExecutionError: The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account.

This error could arise when the account does not have enough funds to:
 - pay for the total gas fee,
 - pay for the value to send.

The cost of the transaction is calculated as `gas * gas fee + value`, where:
 - `gas` is the amount of gas needed for transaction to execute,
 - `gas fee` is the gas fee,
 - `value` is the amount of ether to send to the recipient.

Request Arguments:
  from:                  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
  to:                    0x573802f86c51B61d7Cf620952217eC6Ce0537d2E
  data:                  0x0d84a1b6000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000206dc58d7c175fd0b4b533395f22e2c486d4f254b02116ab0450595f3c061bb955
  gas:                   13075299
  maxFeePerGas:          0.00010006 gwei
  maxPriorityFeePerGas:  0.0001 gwei
  nonce:                 1594