Go-ethereum .EstimateGas function fails

197 Views Asked by At

go-ethereum .EstimateGas function works perfectly when trying to estimate gas if To: is normal user address but when To: is contract address it says: ERROR: execution reverted. PS: I use zkSync era blockchain

approveTx, err := utils.BuildTxForApprove(params.Src, params.Amount, params.From)
        if err != nil {
            log.Err(err)
        }

        gasPrice := new(big.Int)
        gasPrice, ok := gasPrice.SetString("250000000", 10)
        if !ok {
            log.Error().Msg("Error while converting gas price")
        }

        value := new(big.Int)
        value, ok = value.SetString(approveTx.Value, 10)
        if !ok {
            log.Error().Msg("Error while converting gas price")
        }

        tx := ethereum.CallMsg{
            From:     params.From,
            To:       &approveTx.To,
            GasPrice: gasPrice,
            Value:    value,
            Data:     []byte(approveTx.Data),
        }
        log.Info().Msgf("%v", tx)

        estimatedGas, err := b.client.EstimateGas(context.Background(), tx)
        if err != nil {
            log.Info().Msg("ERROR: " + err.Error())
            return txHash, err
        }

this code returns: ERROR: execution reverted but this code works perfectly:

approveTx, err := utils.BuildTxForApprove(params.Src, params.Amount, params.From)
        if err != nil {
            log.Err(err)
        }

        gasPrice := new(big.Int)
        gasPrice, ok := gasPrice.SetString("250000000", 10)
        if !ok {
            log.Error().Msg("Error while converting gas price")
        }

        value := new(big.Int)
        value, ok = value.SetString(approveTx.Value, 10)
        if !ok {
            log.Error().Msg("Error while converting gas price")
        }

        tx := ethereum.CallMsg{
            From:     params.From,
            To:       &params.From,
            GasPrice: gasPrice,
            Value:    value,
            Data:     []byte(approveTx.Data),
        }
        log.Info().Msgf("%v", tx)

        estimatedGas, err := b.client.EstimateGas(context.Background(), tx)
        if err != nil {
            log.Info().Msg("ERROR: " + err.Error())
            return txHash, err
        }

As I said it works perfectly when I use non-contract address but doesn't work when using contract address.

0

There are 0 best solutions below