首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Go-Ethereum错误

Go-Ethereum错误
EN

Ethereum用户
提问于 2020-08-12 10:27:53
回答 1查看 1.1K关注 0票数 0

一直在努力寻找一种方法来估计气体的调用函数。我得到了错误-- Error: VM Exception while processing transaction: revert在ganache上本地,Error: The execution failed due to an exception.在Kovan上。

下面是一个示例可靠性函数:

这就是我的代码的样子:

代码语言:javascript
复制
sig := []byte("withdraw(address)")
methodID := crypto.Keccak256(sig)[:4]
toAddress := common.HexToAddress(myAddr)
paddedAddress := common.LeftPadBytes(toAddress.Bytes(), 32)

var data []byte
data = append(data, methodID...)
data = append(data, paddedAddress...)

sendTo := common.HexToAddress(myAddress)

callMsg := ethereum.CallMsg{
        From:     Wallet.Address,
        To:       &sendTo,
        Gas:      0,
        GasPrice: big.NewInt(0),
        Value:    big.NewInt(0),
        Data:     data,
}
gasAmount, err := eth.EthClient.EstimateGas(context.Background(), callMsg)

为什么我在处理事务时得到抱怨错误: VM异常:还原

EN

回答 1

Ethereum用户

发布于 2020-08-14 05:46:06

下面是我如何解决这个问题的方法:

  1. 正如Dibi91提到的,to地址必须是有效地址。
  2. 在这个PR上找到这种方式,请参考下面的片段。https://github.com/ethereum/go-ethereum/pull/15768/files
代码语言:javascript
复制
var iargs []interface{}
iargs = append(iargs, "0x...") //fill out your arguments

input, err := Abi.Pack("withdraw", iargs...)

sendTo := common.HexToAddress(myAddress)

callMsg := ethereum.CallMsg{
        From:     Wallet.Address,
        To:       &sendTo,
        Gas:      0,
        GasPrice: big.NewInt(0),
        Value:    big.NewInt(0),
        Data:     input,
    }
gasLimit, err := eth.EthClient.EstimateGas(context.Background(), callMsg)
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/86646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档