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: ¶ms.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
相关产品推荐
相关产品推荐

