mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
accounts/abi: estimate gas before send transaction
makes error happen earlier
This commit is contained in:
parent
9d187f0238
commit
47e23f9b87
1 changed files with 15 additions and 14 deletions
|
|
@ -189,7 +189,6 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
|
|||
}
|
||||
}
|
||||
gasLimit := opts.GasLimit
|
||||
if gasLimit == nil {
|
||||
// Gas estimation cannot succeed without code for method invocations
|
||||
if contract != nil {
|
||||
if code, err := c.transactor.PendingCodeAt(ensureContext(opts.Context), c.address); err != nil {
|
||||
|
|
@ -204,6 +203,8 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to estimate gas needed: %v", err)
|
||||
}
|
||||
if opts.GasLimit != nil && opts.GasLimit.Cmp(gasLimit) < 0 {
|
||||
return nil, fmt.Errorf("Gas required is %s, it exceeds limit: %s. An important gas estimation might also be the sign of a problem in the contract code", gasLimit, opts.GasLimit)
|
||||
}
|
||||
// Create the transaction, sign it and schedule it for execution
|
||||
var rawTx *types.Transaction
|
||||
|
|
|
|||
Loading…
Reference in a new issue