You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Go-ethereum EstimateGas函数在zkSync Era合约地址调用时执行回滚

zkSync Era下go-ethereum EstimateGas调用合约地址报错问题

在zkSync Era区块链环境中,使用go-ethereum的EstimateGas函数时,若CallMsg的To字段为普通用户地址,函数可正常估算Gas;但当To字段为合约地址时,会返回错误:ERROR: execution reverted。

报错代码

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
}

正常运行代码

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
}

内容的提问来源于stack exchange,提问作者Piotrek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:43:27